1

I am trying to populate a form in a new window using JQuery but I cant seem to get it to work, it currently opens the new window as desired. But any attempts to populate the form failts.

$( "body" ).delegate( ".propose", "click",function() {  
    var url = './prop_form.php';    
    var win = window.open(url, 'Marketing Docs', 'directories=no,menubar=no,scrollbars=yes,status=no,toolbar=no,location=no,resizable=yes,width=500,height=600');

    $(win).find('input[name=vrm]').val('x');

    if (win.focus) { win.focus(); } 
});

The script should populate a text input called vrm.

Christopher Shaw
  • 763
  • 6
  • 19

1 Answers1

0

Updated (again), I finally got it working after using load event:

      $("body").delegate(".propose", "click", function () {
            var url = './prop_form.php';

            var win = window.open(url, 'Marketing Docs', 'menubar=no,scrollbars=yes,status=no,toolbar=no,location=no,resizable=yes,width=500,height=600');

            $(win).load( function() {  

                $(win.document).find('input[name="vrm"]').val('x');

                $(win.document).find('input[name="vrm"]').focus();

            });
      });

Alternative with setTimeout method

     $("body").delegate(".propose", "click", function () {
        var url = './prop_form.php';

        var win = window.open(url, 'Marketing Docs', 'menubar=no,scrollbars=yes,status=no,toolbar=no,location=no,resizable=yes,width=500,height=600');

        setTimeout(function() { 
             $(win.document).find('input[name="vrm"]').val('x');, 2000); });
      });

I tested the code using Chrome and noticed that one of the window.open parameter attributes is obsolete: directories=yes|no|1|0. Once I removed that parameter the window.open method started working.

jyrkim
  • 2,849
  • 1
  • 24
  • 33