views:

100

answers:

1

I am having trouble getting a form to submit when the name attribute of the submit button is precisely "submit".

Here is the code:

<input onclick="checkForm(document.form_29) && document.form_29.submit();" value="Submit" name="submit" type="button">

Note that we are not using a standard input type of "submit", but rather an input type of "button" with JavaScript being used to submit the form after a validation script (checkForm) has returned true.

The odd thing is that this will not work if and only if the name attribute is "submit". The problem is case-sensitive, so the following (and any other naming, including no name attribute) will work:

<input onclick="checkForm(document.form_29) && document.form_29.submit();" value="Submit" name="Submit" type="button">

I have been looking over the W3C specs for some mention of a reserved name, but I could not find anything. I suspect I am overlooking something really obvious here, so I'm hoping some of y'all out there can see something I can't.

Thanks for any help.

+3  A: 

You're having issues because the name being submit is overriding the form.submit() function reference for that <form>, instead form_29.submit refers to that button, rather than the DOM submit() function.

Nick Craver
D'oh! Thanks! Pretty sure that is the answer...
Jeff Fohl
Yes, this is all Netscape's fault for originally deciding that form fields should be reflected as named properties on the `form` object, rather than just the `form.elements` collection where you'd expect them. This, as well as the reflection of named elements on `document` (and, in IE's even-worse case, `window`) has caused endless problems. We can never be free of this foul mis-design now. Damn their fat, `<blink>`​ing faces.
bobince