Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form submit button will not submit when name of button is "submit" [duplicate]

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.

like image 914
Jeff Fohl Avatar asked Aug 26 '10 00:08

Jeff Fohl


People also ask

Why is the submit button not working?

Why submit button is not working? Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging.

Can I have two or more Submit buttons in the same form?

yes, multiple submit buttons can include in the html form. One simple example is given below.

How do you prevent someone from submitting a form twice?

The disabled property was first introduced by Microsoft but has since been adopted as a standard by the W3C. So when the form is submitted - either by clicking on the submit button or pressing Enter in a text input field - the submit button will be disabled to prevent double-clicking.

Can we change the name of submit button in HTML?

You can change the text of any of the "submit" buttons in the Ares web forms simply by editing the text in the appropriate HTML form, as the actions of these buttons are controlled by the code in the html form.


1 Answers

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.

like image 196
Nick Craver Avatar answered Oct 19 '22 20:10

Nick Craver