Reputation: 4785
I am creating a dynamic form using following code,
function createForm() {
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"./Upload");
f.setAttribute('name',"initiateForm");
f.acceptCharset="UTF-8";
var name = document.createElement("input");
name.setAttribute('type',"text");
name.setAttribute('name',"projectname");
name.setAttribute('value',"saket");
f.appendChild(name);
f.submit();
}
But in Mozilla nothing happens but code works as expected ( in chrome). This code is being called by another function which is invoked by button on click event. After executing this code i am returning false.
Please help me out. Thanks in advance :-)
Upvotes: 1
Views: 4685
Reputation: 438
I had similar error just resolved the same.
If you have just used <form></form>
tag and trying to submit then it gives error in older version of mozill while it works in newer version and other browsers.
The form tag should be under <html><body>
tag. e.g. <html><body><form></form></body></html>
Upvotes: -1
Reputation: 28845
You need to append the new created form to the document, because it was not there on page load.
Try this:
function createForm() {
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"./Upload");
f.setAttribute('name',"initiateForm");
f.acceptCharset="UTF-8";
var name = document.createElement("input");
name.setAttribute('type',"text");
name.setAttribute('name',"projectname");
name.setAttribute('value',"saket");
f.appendChild(name);
document.body.appendChild(f); // added this
f.submit();
}
Upvotes: 2