Search code examples
javascriptjqueryformsinputwindow.opener

How to get a form elements value in the resulting child window (jQuery)


I'm trying to pass the value of an input element from a form on my parent page to its child page. The form element on my opener page, as follows:

<input id="selectedOrgName" type="text" value="SOME_VALUE" name="selected_org_name">

The value of "SOME_VALUE" is dynamic and needs to be passed onto the child page. What I need to do is find that value by referencing the opener's input value.

I've tried a few things, mostly with basic JavaScript and have been unsuccessful -- so, I thought I'd try jQuery, but that is not working either. The code I've tried:

    var abc = openerF.$("[name=selectedOrgName]");

Solution

  • Just do :

    var selectedOrgNameValue = $("#selectedOrgName", window.opener.document).val();
    

    Note that if you dont want / need to load jQuery in the child window, you can do :

     var selectedOrgNameValue = window.opener.jQuery("#selectedOrgName").val();