Mozilla form.submit() not working

戏子无情 提交于 2019-12-07 08:24:38

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();
}

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>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!