Multiple functions validate the same form

Source: Internet
Author: User
Tags functions return

form before submitting, we usually validate its content with client JS, usually by writing a function and then invoking it in the Onsumbit event, as follows:

The following are the referenced contents:
<script language= "JavaScript" >
function Check ()
{
if (Form1.aaa.value = = "") {return false;}
if (Form1.bbb.value = = "") {return false;}
return true;
}
</script>
<body>
<form id= "Form1" Name= "Form1" "method=" Post "action=" Default.asp "onsubmit=" return check (); " >
<p>
<input name= "AAA" type= "text" id= "AAA"/>
</p>
<p>
<input name= "BBB" type= "text" id= "BBB"/>
</p>
<p>
<input type= "Submit" name= "Submission" value= "submitted"/>
</p>
</form>
</body>



If you are using multiple functions to verify the form, how to write the function, how to call it? In fact, it is also very simple, the following example:

The following are the referenced contents:
<script language= "JavaScript" >
function Check1 ()
{
if (Form1.aaa.value = "")
{
return false;
}else{
return true;
}
}
function Check2 ()
{
if (Form1.bbb.value = "")
{
return false;
}else{
return true;
}
}
</script>

<body>
<form id= "Form1" Name= "Form1" "method=" Post "action=" Default.asp "onsubmit=" Return (Check1 () && Check2 ()); " >
<p>
<input name= "AAA" type= "text" id= "AAA"/>
</p>
<p>
<input name= "BBB" type= "text" id= "BBB"/>
</p>
<p>
<input type= "Submit" name= "Submission" value= "submitted"/>
</p>
</form>
</body>



Original:http://www.mzwu.com/article.asp?id=1078



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.