Saturday, March 5, 2011

Submitting a hidden form with javascript on Firefox

Chrome is either more lax, or there isn't standard covering this.

In firefox, make sure the form has a name attribute, does not have a submit button named submit, and lastly, the form must have a parent element. This last bit was a bit of a guess on my part, but this was the solution I needed.
The other two tips are from elsewhere on the web.

Chrome
var f = document.createElement("form");
//... ( add stuff to form )
f.submit();

Firefox is a bit more picky, it must have a parent, and a name:

var f = document.createElement("form");
f.name="myForm";
f.style.visibility="collapse";
document.body.appendChild( f );
//... ( add stuff to form )
f.submit();

No comments:

Post a Comment