Last week I was banging my head against the door trying to perform the simple task of getting a button to submit a form using JavaScript. Normally this wouldn’t present a problem and is accomplished quite easily by adding an onclick event to the button which runs the following JavaScript…
document.forms[0].submit();
However both Internet Explorer and Firefox were giving me script errors…
IE: Object doesn’t support this property of method
FF: document.forms[0].submit is not a function
I struggled with this for around an hour, before realising the stupid mistake I’d made. I’d named the submit button”submit”. Hence, the JavaScript was trying to access an attribute of the object named “submit” rather than the performing the submit method of the form.
So, to avoid confusion and wasted debugging time, simply name your submit button anything other than “submit”!
Filed under: Browser quirks, HTML forms, JavaScript
Saved me hours – honest