Link to home
Start Free TrialLog in
Avatar of mock5c
mock5c

asked on

Submit to hidden form.

Here's some example code that I found.  I would like some assistance in understanding this code.

In the js file, there is this definition:

 $(function(){
   var win = window.open('', "mywindow");
   var myform = $("#myform");
   myform.find("#myattribute").val("X");
   myform.attr("target", "mywindow");
   myform.submit();
});

Then in the form_one.html , there is code this code (in addition to a another form block between <form> tags with a submit button tied to it):

<form style="display: none;" id="myform" action="myprog.cgi?page=/mypage/index.html">
   <input id="myattribute" name="myattribute" />
   <input type="submit">
</form>

Can you please walk me through these lines?  Does the js load when the is first loaded and will it post variables to a hidden form right away?  If so, how is the hidden form displayed?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

This function will be called when the page getting loaded,

 $(function(){

This is to open new window
   var win = window.open('', "mywindow");

create instant of a form using form id
   var myform = $("#myform");

getting value by using the form control name
   myform.find("#myattribute").val("X");

setting up the new window open "target" attribute
   myform.attr("target", "mywindow");

auto form submit
   myform.submit();
});
Avatar of mock5c
mock5c

ASKER

Very informative and helpful.