Why does naming your HTML form submit button submit break things?
The form
element has a method named submit
, but also has the form elements in the form as members.
If you have a button in the form named submit
, you could access it using document.form1.submit
. However, as that is the same name as the submit
method, there is no longer any way of accessing that method. If you use the method to submit the form, that will no longer work.
For example, if you have a button that submits the form using Javascript, that doesn't work:
<input type="button" name="submit" onclick="this.form.submit();" value="try" />
When the button tries to use the submit
method, it will instead get a reference to itself (and an error message when trying to call it, as the button is not a function).
Submit button doesn't work
If you are not using any JavaScript for form validation then a simple layout for your form would look like this:
<form action="formHandler.php" method="post">
<input name="fname" id="fname" type="text" value="example" />
<input type="submit" value="submit" />
</form>
You need to ensure you have the submit
button within the form element and an appropriate action
attribute on the form
element is present.
For a more direct answer, provide the code you are working with.
You may find the following of use: http://www.w3.org/TR/html401/interact/forms.html
jQuery append breaks my HTML form (with submit button)
With:
out.append('<form name="input" action="/createuser" method="get">');
the form DOM element is automatically closed by the browser so everything else is added as new DOM elements but not inside the form.
Here's an alternative method which I like for working with the DOM tree:
out.append($('<form/>', {
name: 'input',
action: '/createuser',
method: 'get',
html:
$('<span/>', {
html: 'Username: '
})
.after(
$('<input/>', { type: 'text', name: 'user' })
.after(
$('<input/>', { type: 'submit', value: 'Submit' })
)
)
}));
Two submit buttons in one form
If you give each one a name, the clicked one will be sent through as any other input.
<input type="submit" name="button_1" value="Click me">
Related Topics
2 Colors in One Placeholder of Input Field
How to Control The Width of a Label Tag
Add Spacing Between Vertically Stacked Columns in Bootstrap 4
HTML - Two Tables Horizontally Side by Side
Can You Have a <Span> Within a <Span>
HTML Embed Autoplay="False", But Still Plays Automatically
How to Have a Video with Transparent Background Using HTML5 Video Tag
How to Create a Triangle in CSS3 Using Border-Radius
How to Show Three Columns Per Row
What Is The Correct Use of Schema.Org Sitenavigationelement
Including a Interactive 3D Figure with Knitr
Responsive Tables, The Smart Way
How to Show an Animation That Is Hidden Behind a Colored Div Using a "Reveal" Div on The Surface
Autoplay Audio on Mobile Safari
Safari Anchors on Links Not Working
How to Get a Textarea to Stretch to Fit Its Content Without Using PHP or JavaScript