Summary of three methods for submitting forms after js validation form

Source: Internet
Author: User

First:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function check (form ){

If (form. userId. value = ''){
Alert ("enter your account! ");
Form. userId. focus ();
Return false;
}
If (form. password. value = ''){
Alert ("Enter your logon password! ");
Form. password. focus ();
Return false;
}
Return true;
}
</Script>

<Form action = "login. do? Act = login "method =" post ">
User Account
<Input type = text name = "userId" size = "18" value = "">
<Br>
Logon Password
<Input type = "password" name = "password" size = "19" value = ""/>
<Input type = submit name = "submit1" value = "login" onclick = "return check (this. form)">

</Form>

Second
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function check (form ){

If (form. userId. value = ''){
Alert ("enter your account! ");
Form. userId. focus ();
Return false;
}
If (form. password. value = ''){
Alert ("Enter your logon password! ");
Form. password. focus ();
Return false;
}
Return true;
}
</Script>

<Form action = "login. do? Act = login "method =" post "onsubmit =" return check (this) ">
User Account
<Input type = text name = "userId" size = "18" value = "">
<Br>
Logon Password
<Input type = "password" name = "password" size = "19" value = ""/>
<Input type = submit name = "submit1" value = "login">

</Form>

Third:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function check (form ){

If (form. userId. value = ''){
Alert ("enter your account! ");
Form. userId. focus ();
Return false;
}
If (form. password. value = ''){
Alert ("Enter your logon password! ");
Form. password. focus ();
Return false;
}

Document. myform. submit ();
}
</Script>

<Form action = "login. do? Act = login "name =" myform "method =" post ">
User Account
<Input type = text name = "userId" size = "18" value = "">
<Br>
Logon Password
<Input type = "password" name = "password" size = "19" value = ""/>
<Input type = button name = "submit1" value = "login" onclick = "check (this. form)">

</Form>

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.