The difference between submit and button in HTML/window.location.href does not jump

Source: Internet
Author: User

<input type= "button" > <input type= "Submit" >

The difference between the two is

The button does not automatically submit the form data, only performs the event handling within the onclick, and if the data is to be submitted, it needs to be added document.form1.submit (); such as

Submit the form data automatically, use it to add verification, put back to verify return ture; or return false;

<input type= "Submit" name= "submit" value= "register" onclick= "return check (); ">

<script>

Funciotn Check ()

{

Verify that the conditional return ture is met;

The condition return false is not satisfied;

}

</script>

[<asp:button onclick= "" Onclientclick= "return Check ()" >

Server-side controls can be added with OnClientClick validation. ]

It is important to note that the <button> </button> control has a special case where the default type of Internet Explorer is "button" and the default value in other browsers is "Submit" when you use the button to add Specifies the Type value.

But the use of asynchronous operations, such as $.ajax (), success will jump after the page, when type= "submit", no validation, after the execution of $.ajax (), and will not jump, will automatically submit the form, the effect is to refresh a bit, and will not jump to its His page.

For example:

  $ ("#save"). Click (function  ()  {                 var supplyvalues = jquery.map ($landlordsupply. Filter ( ": Checked"), function  (a)  {                     return $ (a). Val ();                 })                  $.getjson ("/webserver/addhouseinfo.ashx", {  " Type ": " addhousefacility ", " facility ":  supplyvalues.join ()  }, function  (R)   {                     if  (r.err ==  "0")  {              &Nbsp;          alert ("published successfully");                          window.location =  "submithouse.aspx?ti="  + math.random ();                     }                      else {                         alert (R.err);                     };                 });                 return false; 
This sentence must be added before the form can be submitted, and this sentence cannot be added to
Getjson () inside, Async added to the inside no effect, only after the asynchronous execution//plus this sentence, make a judgment, will not continue to execute the Submit. })

The difference between submit and button in HTML/window.location.href does not jump

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.