The difference between a submit and a button in HTML

Source: Internet
Author: User
Tags servervariables

Submit is one of the buttonsSpecial Cases, also a button, which automatically integrates the commit action.if the form after the click on the Submit button needs to be processed with JS (including input validation) before submitting, it is usually necessary to change the submit to a button, that is, to cancel its automatic submission behavior, otherwise, will result in the submission two times the effect,For dynamic Web pages, this is the database operation two times. Or, add return True or False when validating with submit. The Submit and button, both of which are displayed as buttons, appear to be buttons, unlike the type attribute and the event that the response occurs.the submit form is submitted and the button does not submit the form.The main difference between the two is:
Submission
defaults to form submission, and you can submit a form. The button responds to user-defined events and does nothing if it does not specify an event handler such as the onclick. Of course, the button can also complete the work of the form submission. INPUT Type=submit send form, press ENTER to submit form INPUT Type=button is a simple button function, submitted is innertext
Detailed comparison of ===============submit and buttons ===================================submit:Special button, will automatically submit the form's data, the OnClick method does not add the return will automatically commit, does not play the role of constraints, therefore, the use of submit requires validation please add return True or FALSE.Example: <input type= "Submit" name= "submit" value= "register" onclick= "return check ();" In JS, write return True when judging. or return False; button: The normal button does not automatically submit the form data. Can be explicitly submitted in JS: Document.form1.submit (), Use occasions: a page has multiple submit buttons, Depending on the user's actions to determine exactly which controller to commit, in this case, you need to determine the user's operation in JS, and then according to the operation to assign a value to Document.form1.action and Document.form1.submit () to submit  = ============== If you want to put all the commits in a servlet, what to do ==================  the submitted button is also the HTML component, so it can also be obtained by GetParameter (), Then the parameters of the GetParameter () also need to be fixed   parameter is the name of the Submit button for all forms, of course the name of the Submit button is the same as to unify the operation in a servlet based on the value of the Submit button  ========== ============ the settings for the path ===================================a. Write the path directly in the page, such as href= "jsp/a.html" indicates access to the peer directory, This example indicates that there is a JSP folder in the peer directory that accesses the a.html file in the folder B. A direct write path in Java, such as Response.sendredirect ("jsp/a.jsp"), indicates that there is a JSP folder under the project root directory. You are accessing the a.jsp file in the folder C. If you find that the above settings in the browser address bar is incorrect, you can take an absolute path to the wording:/project name/folder name/file name   But for those working on the Web UI, it should be noted that Use submit to improve page usability: After using submit, the page supports keyboard enter operation, and many web software designers may not notice the unity of submit. The page does not support the ENTER key after the button is used. Therefore, you need to support the ENTER key, you must set a submit, the default enter key to the first submit to the page operation.  <input type= "Submit" name="B1" value= "Submit" onclick= "Bt_submit_onclick ()" > Execute OnClick, go to action. Can be automatically submitted without the onclick, so that onclick here can not.  <input type= "button" Name= "B1" value= "Commit" onclick= "Bt_submit_onclick ()" > Execute OnClick, jump file in JS file control, Submission requires OnClick. If there are no onclick  here for example:
type= "Submit"<formID= "Frm1"Action= "<%=request." ServerVariables ("script_name ")%>"method=" POST "onsubmit=" return Check_submit (This) "><inputID= "Btnconfirm"type= "Submit"value= "OK"name= "Btnconfirm"></form>type= "button"<formID= "Frmaddmodi"Action= "<%=request." ServerVariables ("script_name ")%>"method=" post "name=" Frmaddmodi "><inputID= "Btnconfirm"type= "button"value= "OK"name= "Btnconfirm"OnClick= "Check (frmaddmodi);"/></form>

The difference between a submit and a button in HTML

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.