Returnfalse will prevent form submission. Basically, there are several points to note about onsubmitreturnfalse. You must be familiar with background programming. 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
The Code is as follows:
Function chkinput (form)
{
If (form. title. value = "")
{
Alert ("Enter the article title! ");
Form. title. select ();
Return false;
}
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:
The Code is as follows: