Differences between submit and button in javaScript _ basic knowledge
Source: Internet
Author: User
Submit is a special case of a button and also a kind of button. It automatically integrates the submit action. Both submit and button are displayed in the form of buttons. They both look like buttons, what is different is that the submit attribute and the event where the response is sent is a special case of the button and also a kind of button. It automatically integrates the submitted action.
If the form needs to be processed (including input verification) by clicking the submit button and then submitted, you must change the submit to the button to cancel the automatic submission. Otherwise, it will result in two submissions. For dynamic web pages, that is, two database operations. Alternatively, return true or false is added for verification when submit is used.
Both submit and button are displayed in the form of buttons. They both look like buttons. what is different is that the type attribute and the event where the response is sent, the submit will submit the form, and the button will not submit the form. the main differences between the two are:
By default, submit is used for form submission. You can submit a form (form ).
Button responds to user-defined events. If you do not specify event processing functions such as onclick, it does not do anything. of course, the button can also complete form submission. INPUT type = submit: Send the form. Press enter to submit the form.
INPUT type = button is a simple button function, and innerTEXT is submitted.
=================== Detailed comparison between submit and button ================================== ======================
Submit: A special button that automatically submits data in the form. The onClick method is automatically submitted without return, and does not apply constraints,
Therefore, you need to add return true or false for verification when using submit.
Example: Return true; or return false; button: A common button, which does not automatically submit form data. It can be explicitly specified in JS.
Intersection: document. form1.submit (): When a page has multiple submit buttons, you need to determine the Controller to which the page is submitted based on your operations. In this case, you need to judge the user's operations in JS, and then give the document according to the operation. form1.action value and document. form1.submit () to submit
================== If you want to handle all the commits in a servlet, how to Do This ============================
The submitted button is also an HTML component, so you can also get it through getParameter (), so the parameters of getParameter () need to be fixed.
The parameter is the name of the submit button for all forms. Of course, the name of the submit button must be the same so that it can be operated differently in a servlet based on the value of the submit button.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.