日期:2014-05-17  浏览次数:20516 次

关于form表单验证未通过却提交的问题
HTML code




<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<script language="JavaScript" type="text/javascript">
 function chk_reg_input(form)
 {
    if(form.userName.value==""){
    alert("请输入用户名");
    form.username.focus();
    return false;}
 
    if(form.password.value==""){
    alert("请输入密码");
    form.password.focus();
    return false;}
    
    if(form.password_confirm.value==""){
    alert("请输入密码");
    form.password_conform.focus();
    return false;}

    if(form.password_confirm.value != form.password.value){
    alert("两次密码不一致");
    form.password.focus();
    return false;}    
    
    if(form.email.value==""){
    alert("请输入邮箱");
    form.email.focus();    
    return false;}
    
    if(form.user_title.value==""){
    alert("请输入职务");
    form.user_title.focus();
    return false;
    }
    if(form.department.value==""){
    alert("请输入单位");
    form.department.focus();    
    return false;}
    
     if(form.tel_num.value==""){
    alert("请输入电话");
    form.tel_num.focus();    
    return false;}
    
    if(form.message.value==""){
    alert("请输入备注信息");
    form.message.focus();    
    return false;}
    
    
    
    return  true;
 }

 </script>
<style type="text/css"> 
td { 
border-right: 1px solid #C1DAD7; 
border-bottom: 1px dashed #C1DAD7; 
padding: 7px 6px 6px 6px; 
color: #4f6b72; 
} 

</style>
<link href="main.css" rel="stylesheet" type="text/css" />

        <div id="register" style=" align:center;text-align:center;margin-top:80px;margin-left:150px;background-image:url(../images/registerbg3.png);width:492px;height:500px;"> 
            <form action ="register2.php" method="post" name="register" onsubmit="return chk_reg_input(this.form)">
                <table style="margin:auto">
                    <tr>    
                        <td style="width:2px ;color:#FF0000;text-align:right">*</td><td style="text-align:left">用户名:</td>
                        <td><input type="text" name="userName" size="20"/> </td>
                    </tr>
                    <tr>    
                        <td style="width:2px ;color:#FF0000;text-align:right">*</td><td style="text-align:left">密码:</td>
                        <td><input type="password" name="password" size="20"/> </td>
                    </tr>    
                    <tr>    
                        <td style="width:2px ;color:#FF0000;text-align:right">*</td><td style="text-align:left">确认密码:</td>
                        <td><input type="password" name="password_confirm" size="20"/> </td>
                    </tr>                    
                    <tr>            
                        <td style="width:2px ;color:#FF0000;text-align:right">*</td><td style="text-align:left">Email:</td>
                        <td><input type="text" name="email" size="20"/></td>
                    </tr>
                    <tr>    
                        <td style="width:2px;color:#FF0000;text-align:right">*</td><td style="text-align:left">单位名称:</td>