提交表单时执行func方法

<%@ page contentType="text/html; charset=utf-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>用户注册</title>
 <script language="javascript">
 <!--
  function MyForm(){
     msg.innerHTML="debug::in function";
    var username = document.form1.username.value;
    var msg = document.getElementById("msg");
    if(username.length==0){
        msg.innerHTML="[ 提示:用户名不能为空! ]";
        document.form1.username.focus();
    return false;
    }

    var pass = document.form1.password.value;
    if(pass.length==0){
        msg.innerHTML="[ 提示:密码不能为空! ]";
        document.form1.password.focus();
    return false;
    }
    
    var pass1 = document.form1.password1.value;
    if(pass1.length==0){
        msg.innerHTML="[ 提示:确认密码不能为空! ]";
        document.form1.password1.focus();
    return false;
    }
    
    if(pass1!=pass){
        msg.innerHTML="[ 提示:您两次输入的密码不一致! ]";
        document.form1.passwoid.focus();
    return false;
    }
    
    var mail = document.form1.mail.value;
    if(mail.length==0){
        msg.innerHTML="[ 提示:E_mail不能为空! ]";
        document.form1.mail.focus();
    return false;
    }
    
    var i = form1.mail.value.indexOf("@");
    var j = form1.mail.value.indexOf(".");
    if((i<0)||(j<0)||(i-j>0))
    {
        msg.innerHTML="[ 提示:您输入的E_mail格式不正确,请正确输入! ]";
        document.form1.mail.focus();
    return false;
    }
    msg.innerHTML="";
    return true;
 }
 -->

 </script>
 </head>

 <body οnlοad="document.form1.username.focus()">
 <form id="form1" name="form1" method="post" action="" οnsubmit="return MyForm()">
 <table width="389" border="1" align="center" cellpadding="5">
     <tr>
       <td colspan="2"><div align="center">用户注册<br /></div></td>
     </tr>
     <tr>
      <td colspan="2" align="center" bordercolor=""
 bgcolor="">
 <font color="red"><span id="msg">${error}</span> </font>
 </td>
     </tr>
     <tr>
       <td width="71">用户名:</td>
       <td width="286"><label>
         <input name="username" type="text" id="username" size="20" />
       </label>
       *(必填)</td>
     </tr>
     <tr>
       <td>用户密码:</td>
       <td><label>
         <input name="password" type="password" id="password" size="20" />
       </label>
         *(必填)</td>
     </tr>
     <tr>
       <td>重复密码:</td>
       <td><label>
         <input name="password1" type="password" id="password1" size="20" />
       </label>
       *(必填)</td>
     </tr>
     <tr>
       <td>电子邮件:</td>
       <td><label>
         <input name="mail" type="text" id="mail" size="25" />
       </label>
       *(必填)</td>
     </tr>
     <tr>
       <td>电话:</td>
       <td><label>
         <input name="tel" type="text" id="tel" size="22" />
       </label></td>
     </tr>
     <tr>
       <td>QQ:</td>
       <td><label>
         <input name="qq" type="text" id="qq" size="22" />
       </label></td>
     </tr>
     <tr>
       <td colspan="2"><label>
           <div align="center">
             <input type="submit" name="Submit" value="注册" /> 
    
             <input type="reset" name="Submit2" value="重置" />
               </div>
       </label></td>
     </tr>
   </table>
 </form>
 </body>
 </html>

 

转载于:https://www.cnblogs.com/haoyuanyuan/archive/2013/03/14/2959235.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值