In our previous article, we introduced to you JavaScript several methods to implement form submission. We all know that verification is required before the form can be submitted, so we will give it to you today Introduce three methods of submitting the form after js verification.
The first type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <script type= "text/javascript" >
function check(form) {
if (form.userId.value=='') {
alert( "请输入用户帐号!" );
form.userId.focus();
return false;
} www.jbxue.com
if (form.password.value==''){
alert( "请输入登录密码!" );
form.password.focus();
return false;
}
return true;
}
</script>
<form action= "login.do?act=login" method= "post" >
用户帐号
<input type=text name= "userId" size= "18" value= "" >
<br>
登录密码
<input type= "password" name= "password" size= "19" value= "" />
<input type=submit name= "submit1" value= "登陆" onclick= "return check(this.form)" >
</form>
|
Copy after login
The second type
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <script type= "text/javascript" >
function check(form) {
if (form.userId.value=='') {
alert( "请输入用户帐号!" );
form.userId.focus();
return false;
}
if (form.password.value==''){
alert( "请输入登录密码!" );
form.password.focus();
return false;
}
return true;
}
</script>
<form action= "login.do?act=login" method= "post" onsubmit= "return check(this)" >
用户帐号
<input type=text name= "userId" size= "18" value= "" >
<br> www.jbxue.com
登录密码
<input type= "password" name= "password" size= "19" value= "" />
<input type=submit name= "submit1" value= "登陆" >
</form>
|
Copy after login
The third type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <script type= "text/javascript" >
function check(form) {
if (form.userId.value=='') {
alert( "请输入用户帐号!" );
form.userId.focus();
return false;
}
if (form.password.value==''){
alert( "请输入登录密码!" );
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
<form action= "login.do?act=login" name= "myform" method= "post" >
用户帐号
<input type=text name= "userId" size= "18" value= "" >
<br>
登录密码
<input type= "password" name= "password" size= "19" value= "" />
<input type=button name= "submit1" value= "登陆" onclick= "check(this.form)" >
</form>
|
Copy after login
Summary:
I believe that after studying this article, everyone will have a certain understanding of the JavaScript verification submission form. You can follow this article I am doing more expansion on the content, so that this article can serve as an inspiration!
Related recommendations;
Several ways to submit forms using JavaScript
Javascript processing form example (javascript submission form)
Brief description of how JavaScript submits a form (Using JavaScript Submit Form)
The above is the detailed content of Sharing three methods for JavaScript submission form verification. For more information, please follow other related articles on the PHP Chinese website!