Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 931 Bytes

do-not-use-submit-to-name-a-submit-button.mdx

File metadata and controls

26 lines (19 loc) · 931 Bytes
category created tags title
Practice
2021-03-04
HTML
Do not use submit to name a submit button

Given a form element, we often call the submit() method to submit the form after validating its fields.

If the submit button of the form has either name="submit" or id="submit" attribute, then formEle.submit will return the submit button instance. As a result, formEle.submit() throws an exception because it's not an actual function anymore.

We can face the similar issue when using special properties of form such as reset, length, method.

<!-- Do NOT -->
<button type="submit" name="submit">Submit</button>
<button type="submit" id="submit">Submit</button>

<!-- Do -->
<button type="submit" name="submitButton">Submit</button>

See also