Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup window return value

Tags:

javascript

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.

like image 268
yesiamconfused Avatar asked Feb 01 '11 19:02

yesiamconfused


1 Answers

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>
like image 68
John K. Avatar answered Sep 22 '22 16:09

John K.