The use and difference of the form's Submit and onsubmit

Source: Internet
Author: User

Order of Occurrence: onsubmit, submit
1. Prevent form Bill of lading:
<script>
function Submitfun () {
Logical judgment
return true; Allow form submission
Logical judgment
Return false;//does not allow form submission
}
</script>
<form onsubmit= "Reture submitfun (); >//Note This cannot be written as onsubmit= "Submitfun ();" Otherwise, always submit the form
</form>
2.onsubmit () and submit ():
<script>
function Fun ()
{
Alert ("Form_submit");
}
</script>

<form onsubmit= "Fun ()" >
<input type= "Submit" id= "AAA" value= "Submit" > <!--can eject form_submit-->
<input type= "button" id= "BBB" value= "Onclick_submit" onclick= "Document.forms[0].submit ()" >
<!--
The form will be submitted, but will not run fun () because the onsubmit event cannot be triggered in this way (in IE environment)
Submitting a form directly with the script DoCumetn.formName.submit () will not touch the onsubmit () event of the publication order.
-
<input type= "button" id= "BB1" value= "Onclick_onsubmit" onclick= "Document.forms[0].onsubmit ()" >

<!--will trigger fun () Parameters--
</form>

The use and difference of the form's Submit and onsubmit

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.