Popup window return value
I hope someone may be kind enough to help me with this issue.
What I am trying to do I return a value from a popup window into the parent window that launched it using javascript.
What I have tried is calling (as read on various websites)
window.opener.document.forms[0].textField.value = 'value'
but while this does not produce any errors it does not change the field value.
I have tried searching on the net for a solution to this but there as so many sites relating to 'pop up return value' on google, results dating back to 2000, many seem to conflict each other so I am somewhat confused.
Ideally what I would prefer to do is have the pop up window wait for a decision to be made (either yes or no), and have a true or false value return to the calling function from the parent window. As the reason for this, is that I have a form the uses onsubmit to call a javascript function to confirm weather to continue on not. I was using a dialog to return a true false value, but 开发者_如何学编程now trying to do it with a pop up so I can include images and various other information.
Hopefully I have explained this well enough and someone can help me with a solution.
Thanks for your time.
You can reference the window that opened the popup from the popup... In this example, something on the popup window calls this function (which exists on the popup window) passing in the "val"...
<script language="javascript">
function GetRowValue(val)
{
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val;
window.close();
}
</script>
Here is the dissection of Django admin's approach: Howto: javascript popup form returning value for select like Django admin for foreign keys. It is undoubtedly more complicated, but eventually this technique will get you there.
use this in parent page
var answer = window.open(<your page and other arguments>)
if (answer == 1)
do some thing
in child page
window.returnValue = 1;
Try the following:
window.opener.document.getElementById("sizeId" + rn).value
Above size id will match the parent window id of input type where you want to return the values.
精彩评论