I am trying to create and submit a form with pure Javascript in a Firefox extension. However, even with the most basic form, the browser console continues to say:
TypeError: form.submit is not a function
I searched and read several posts on this subject, but they did not address this specific problem. A common mistake is to have an input named "submit", but this is not the case here.
Here is my code inspired by this wonderful JavaScript post request post on how to submit a form :
var form = document.createElement("form");
form.action = "http://example.com";
form.method = "POST"
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "submit");
hiddenField.setAttribute("name", "sub");
hiddenField.setAttribute("value", "send");
form.appendChild(hiddenField);
var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
body.appendChild(form);
doc.documentElement.appendChild(body);
form.submit();
I am new to Javascript, so it is likely that I am making a trivial mistake. Can someone let me know how to fix this?