A description of the difference between submit and button in JavaScript _ basics

Source: Internet
Author: User
Submit is a special case of a button and a button that automatically integrates the commit action.
If the form needs to be processed with JS after clicking the submit button (including input validation), usually have to change the submit button, that is, to cancel the automatic submission of the behavior, otherwise, will result in the submission of two results, for dynamic Web pages, that is, the database operation two times. or return TRUE or FALSE when you use submit for validation.
Both the Submit and button are displayed as buttons, and appear to be buttons, unlike the type attribute and the event in which the response is sent, and submit submits the form, and the button does not submit the form. The main difference between the two is:
Submit defaults to form submission, and you can submit forms (form).
The button responds to user-defined events and does nothing if you do not specify an event handler function such as onclick. Of course, a button can also complete the work of the form submission. INPUT type=submit Send form, press ENTER to submit the form

INPUT Type=button is a simple button function, submitted by the InnerText

Detailed comparison of ===============submit and button ===================================
Submit: Special button, will automatically submit the data of the form, the OnClick method does not add return will automatically submit, does not play a binding role,
Therefore, when you use submit, you need to verify that you add return True or FALSE.
Example: <input type= "Submit" name= "submit" value= "registered" onclick= "return check ();" In JS, when the judgment of the time to write return true; or return false; Button: Normal buttons do not automatically submit the form data. Can be explicitly mentioned in JS

Pay: Document.form1.submit (), the use of occasions: a page has multiple submit buttons, according to the user's operation to determine exactly which controller to submit to, in this case, you need to judge the user's operation in JS, The document.form1.action is then assigned and Document.form1.submit () is submitted according to the operation.

=============== If you want all the submissions to be handled in a servlet, what do you do? ==================
The submitted button is also an HTML component, so it can also be obtained by GetParameter (), so the parameters of getparameter () need to be fixed.

The parameter is the name of the Submit button for all forms, and of course the name of the Submit button is the same to unify in a servlet to distinguish actions based on the value of the Submit button

Attached code:

JS file

When using submit, the JSP page

When you use the button, the JSP code
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.