javascript 表单提交

来源:互联网 发布:什么是黑箱 人工智能 编辑:程序博客网 时间:2024/05/29 16:28
<head> 

 <script type="text/javascript">
 
 
     
      function saveCheck()
    {
      if(document.form.staid.value==""||document.form.staid.value==null)
      {
         alert("员工编号不能为空!");
         document.form.staid.value="";
         document.form.staid.focus();
        return false;
      }
      if(document.form.staname.value==""||document.form.staname.value==null)
      {
         alert("姓名不能为空!");
         document.form.staname.value="";
         document.form.staname.focus();
        return false;
      }
     if(document.form.stasex.value==""||document.form.stasex.value==null)
      {
         alert("姓别不能为空!");
         document.form.stasex.value="";
         document.form.stasex.focus();
        return false;
      }
      if(document.form.staage.value==""||document.form.staage.value==null )
      {
         alert("年龄不能为空!");
         document.form.staage.value="";
         document.form.staage.focus();
        return false;
      }
     
     /* if(document.form.stamobilephone.value==""||document.form.stamobilephone.value==null&&document.form.stamobilephone.value=="/^1[3|4|5|8][0-9]\d{4,8}$/")
      {
         alert("手机号不能为空!");
         document.form.stamobilephone.value="";
         document.form.stamobilephone.focus();           
        return false;       
      }*/
       var objValue=stamobilephone.value;
          if(objValue == null || objValue == ''){
           return true;
      }
              var reg=/^1[3|4|5|8][0-9]\d{4,8}$/;
         if(!reg.test(objValue)){
              alert("不是完整的11位手机号码!");
             stamobilephone.focus();
              return false;
          }

    
      /*   var reg=/^1[3|4|5|8][0-9]\d{4,8}$/;
      if(!reg.test(stamobilephone))
      {
             alert("不是完整的11位手机号码!");
             stamobilephone.focus();
            return false;
         }*/
   
     
      if(document.form.staemail.value==""||document.form.staemail.value==null )
      {
         alert("邮箱不能为空!");
         document.form.staemail.value="";
         document.form.staemail.focus();
        return false;
      } 
       if(document.form.staqq.value==""||document.form.staqq.value==null )
      {
         alert("QQ不能为空!");
         document.form.staqq.value="";
         document.form.staqq.focus();
        return false;
      } 
       if(document.form.staaddress.value==""||document.form.staaddress.value==null )
      {
         alert("地址不能为空!");
         document.form.staaddress.value="";
         document.form.staaddress.focus();
        return false;
      } 
     /* var code=(document.getElementById("staid"));
      if(code.value==null)
      {
        alert("员工编号不能为空!");
        return false;
      }
      else
      {
        if(deleteNull(code)=='')
        {
           alert("员工编号不能为空!");
           return false;
        }
      }
   
       var addresse=(document.getElementById("staaddress"));
      if(name.value==null)
      {
        alert("地址不能为空!");
        return false;
      }
      else
      {
        if(deleteNull(address)=='')
        {
           alert("地址不能为空!");
           return false;
        }
      }*/
   }
 
 </script>
  </head>
 
  <body>
 
    <form action="index.jsp" method="post" name="form" onsubmit="return saveCheck()">
   
      <h2 align="center">&nbsp;员工信息添加</h2>
      <table align="center">
        <tr>
          <td>编号:</td>
          <td><input type="text" name="staid" id="staid"/></td>
        </tr>
         <tr>
          <td>姓名:</td>
          <td><input type="text" name="staname" id="staname"/></td>
        </tr>
         <tr>
          <td>性别:</td>
          <td><input type="text" name="stasex" id="stasex"/></td>
        </tr>
         <tr>
          <td>年龄:</td>
          <td><input type="text" name="staage" id="staage"/></td>
        </tr>
         <tr>
          <td>手机:</td>
          <td><input type="text" name="stamobilephone" id="stamobilephone"/></td>
        </tr>
         <tr>
          <td>邮箱:</td>
          <td><input type="text" name="staemail" id="staemail"/></td>
        </tr>
         <tr>
          <td>Q Q:</td>
          <td><input type="text" name="staqq" id="staqq"/></td>
        </tr>
         <tr>
          <td>地址:</td>
          <td><input type="text" name="staaddress" id="staaddress"/></td>
        </tr>
        <tr>
          <td>
              <input type="submit" value="提交" />
          </td>
          <td><input type="reset" value="重置"/>
          </td>
        </tr>
      </table>
    </form>
   
  </body>
</html>

原创粉丝点击