Two submission buttons for HTML submit and button

Source: Internet
Author: User
Tags button type

Transferred from: http://baiying.blog.51cto.com/1068039/1319784

There are two types of HTML buttons:

<input type= "button" value= "Login" onclick= "login ()"/>

and <button onclick= "login ()" > Login </button>

The two seem to look the same on the page, but there are differences between the two types.

1, if in <form id= "LoginForm" name= "LoginForm" action= "<%=path%>/hdlogin/login.action" method= "POST" ></ Form>

tab, use <input type= "button" value= "Login" onclick= "login ()"/> to submit a form,

You must write <input type= "submit" value= "Login" onclick= "login ()"/>

or Document.loginForm.submit (), otherwise the form will not be submitted.

2, if you use <button onclick= "login ()" In form > Login </button> just click to submit.

<button type= "Submit" value= "Login" onclick= "login ()"/>.

Today in the use of <button></button>, I again in the JS control form submission, the result of this action is always inexplicably walk two times!

The root cause is that the form was submitted two times, one <button></button> one is Document.loginForm.submit ();

This mistake is very covert, we should pay attention to it later.

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.