Javascript: onsubmit = returnfalse blocks form submission

Source: Internet
Author: User
Returnfalse blocking form submission does not work. Today, this problem has plagued me for a long time. I have found a lot of information on the Internet. Basically, there are several points to note about onsubmitreturnfalse: 1. the return value of return. If return in a function has a return value ,... syntaxHighlighter. all (); return false: Blocking form submission does not work. Today, this problem has plagued me for a long time and I have found a lot of information online, basically, there are several points to note about onsubmit = return false:
 
1. For the return value problem, once a return value exists in the function, the following statement is not executed and the return value directly jumps to the place where the function is called. In the following PHP function code, if the first if condition matches, the function value returns a Boolean false value, which can return the value of a function and jump out of the function. if you encounter a return statement, the program stops execution in that line of code, and the execution control will immediately return to the code that calls the program.
 
Function chkinput (form)
{
If (form. title. value = "")
{
Alert ("Enter the article title! ");
Form. title. select ();
Return false; // note that return (false) cannot be written; 2009.12.15
}
 
If (form. content. value = "")
{
Alert ("the text cannot be blank @!! ");
Form. content. select ();
Return false;
}
 
Return true;
}
2. When will the onsubmit event be triggered when the onsubmit attribute of form is triggered? The onsubmit event occurs when the confirmation button in the form is clicked. The reasons for not triggering are as follows:
 
A. The onsubmit attribute will be triggered only when the form uses A button such as input: submit to submit. Otherwise, it will not be triggered. If a common input: button is used, a javascript function is specified in the onclick attribute. In this function, the submit () function of form is executed instead of the onsubmit attribute.
 
B. First read a piece of 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.