An introduction to the difference between a submit and a button in javaScript

  • 2020-03-26 21:35:48
  • OfStack

Submit is a special case of a button, a type of button, and it automatically integrates the submit action.
If the form needs to be processed with JS after clicking the submit button (including input validation) and then submitted, it is usually necessary to change the submit to button, that is, to cancel its automatic submission behavior. Otherwise, it will result in the effect of submitting twice. For dynamic web pages, that is, two database operations. Or return true or false when using submit to verify.
Submit and button are both presented in the form of buttons, which look like buttons. The difference is that on the type attribute and the event where the response is sent, submit will submit the form, while button will not submit the form.
Submit defaults to a form submission, and you can submit a form (form).
A button responds to a user-defined event and does nothing without specifying an event handler such as onclick

INPUT type=button is just the function of a button, and the innerTEXT is submitted

= = = = = = = = = = = = = = = the submit detailed contrast and button = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Submit: a special button will automatically submit the data of the form, and the onClick method will automatically submit without return, which will not serve as a constraint.
So, return true or false when using submit.
Example: < Input type="submit" name=" submit" value=" note "onClick=" return check();" > , return true in JS; Or return false. Button: a normal button that does not automatically submit form data. It can be raised explicitly in JS

Submission :document.form1.submit(), usage: a page has multiple submit buttons, need to determine which controller to submit to according to the user's operation, in this case, need to judge the user's operation in JS, and then according to the operation to the document.form1.action value and document.form1.submit() to submit

= = = = = = = = = = = = = = = if you want to be good all submitted in a servlet processing, how to do it = = = = = = = = = = = = = = = = = =
The submitted button is also an HTML component, so it can also be obtained through getParameter(), so the parameter of getParameter() also needs to be fixed

The parameter is the name of the submit button of all forms. Of course, the name of the submit button must be the same in order to differentiate the operation according to the value of the submit button in a servlet

The attached code:

Js file
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201310/201310201455091.gif? 2013920145543 ">  
When you submit, the JSP page
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201310/201310201457356.gif? 2013920145754 ">  
When using button, the JSP code
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201310/201310201459117.gif? 2013920145927 ">

Related articles: