I don't follow completely, but I get the general idea. First off, the correct way to do:
Code:
document.form2.submit()
would actually be:
Code:
document.forms['form2'].submit()
or:
Code:
document.forms.form2.submit()
The forms collection can usually be assumed, but if there is any other object on the page that could possibly be thought to be 'form2', there will be problems. Or a reference could be created for the form in some other unambiguous manner as a variable, as I did in my code. then the form may be referenced via that variable.
Now, let me break down how my previous code works, it may help answer your current question.
onclick="var f=this.form;
window.open('',f.target,'width=300, height=200, location, resizable');
setTimeout(function(){f.submit();},100);return false;"
simply establishes a reference to the current form, but only in the scope of the current onclick event, thus protecting it from any other var f on the page.
Code:
window.open('',f.target,'width=300, height=200, location, resizable');
The window.open method is opening an empty ('') window and naming it (f.target) after the target attribute of the form. The rest are just the specifications for the window, which can be configured however one likes.
Code:
setTimeout(function(){f.submit();},100);"
Now that we've given the the window a chance to open, after 100 milliseconds, submit the form. The form's target is the newly opened window's name, so its action (complete with any method data) opens in the already opened but empty window.
By returning false we ensure that there will be no automatic submission (which would happen too soon for the window we are opening) of the form, as can happen when the default (in this case the only visible) input of a form is activated.
Bookmarks