Home  >  Article  >  Web Front-end  >  Sharing three methods for JavaScript submission form verification

Sharing three methods for JavaScript submission form verification

黄舟
黄舟Original
2017-11-18 14:58:502072browse

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:

<script type="text/javascript">
         function check(form) {
          if(form.userId.value==&#39;&#39;) {
                alert("请输入用户帐号!");
                form.userId.focus();
                return false;
           } www.jbxue.com
       if(form.password.value==&#39;&#39;){
                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>

The second type

<script type="text/javascript">
         function check(form) {
          if(form.userId.value==&#39;&#39;) {
                alert("请输入用户帐号!");
                form.userId.focus();
                return false;
           }
       if(form.password.value==&#39;&#39;){
                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>

The third type:

<script type="text/javascript">
         function check(form) {
          if(form.userId.value==&#39;&#39;) {
                alert("请输入用户帐号!");
                form.userId.focus();
                return false;
           }
       if(form.password.value==&#39;&#39;){
                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>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn