js客户端验证,点提交出现对话框,但仍进入Servlet中?(50分)

F

ff_ff

Unregistered / Unconfirmed
GUEST, unregistred user!
<%@ page contentType=&quot;text/html;charset=GBK&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<link href=&quot;rs/css.css&quot;
rel=&quot;stylesheet&quot;
type=&quot;text/css&quot;>
<title>新用户注册</title>
</head>
<body>
<center>
<script language=&quot;JavaScript&quot;>
function checkForm()
{
//非空
if(loginForm.name.value == &quot;&quot;)
{
alert(&quot;用户名不能为空!&quot;);
Form1.txtTitle.focus();
return false;
}

}
</script>
<h3> </h3>
<h3>新用户注册</h3>
<hr>
<form name=&quot;loginForm&quot;
method=&quot;post&quot;
action=&quot;RegServlet&quot;
onsubmit=&quot;return checkForm()&quot;>
<table width=&quot;37%&quot;
border=&quot;1&quot;>
<tr>
<td width=&quot;39%&quot;>用户名:</td>
<td width=&quot;61%&quot;><input type=&quot;text&quot;
name=&quot;name&quot;></td>
</tr>
<tr>
<td>密码:</td>
<td><input type=&quot;password&quot;
name=&quot;password&quot;></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type=&quot;text&quot;
name=&quot;affirm&quot;></td>
</tr>
<tr>
<td>番号:</td>
<td><input type=&quot;text&quot;
name=&quot;dept&quot;></td>
</tr>
</table>
<p>
<input type=&quot;submit&quot;
name=&quot;Submit&quot;
value=&quot;提交&quot;></td>

<input type=&quot;reset&quot;
name=&quot;reset&quot;
value=&quot;重置&quot;></td>

</form>
</center>
</body>
</html>
 
<form name=&quot;loginForm&quot;
method=&quot;post&quot;
action=&quot;RegServlet&quot;
onsubmit=&quot;return checkForm()&quot;>

function checkForm()
{
//非空
if(loginForm.name.value == &quot;&quot;)
{
alert(&quot;用户名不能为空!&quot;);
Form1.txtTitle.focus(); //好像应该是“loginForm.name.focus(); ”
return false;
}

}
 
<%@ page contentType=&quot;text/html;charset=GBK&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<link href=&quot;rs/css.css&quot;
rel=&quot;stylesheet&quot;
type=&quot;text/css&quot;>
<title>新用户注册</title>
</head>
<body>
<center>
<script language=&quot;JavaScript&quot;>
function checkForm()
{
//非空
if(loginForm.name.value == &quot;&quot;)
{
alert(&quot;用户名不能为空!&quot;);
loginForm.name.focus();
return false;
}
else
if(loginForm.password.value == &quot;&quot;)
{
alert(&quot;密码不能为空!&quot;);
loginForm.password.focus();
return false;
}
else
if(loginForm.affirm.value == &quot;&quot;)
{
alert(&quot;请确认密码&quot;);
loginForm.affirm.focus();
return false;
}
else
if(loginForm.dept.value == &quot;&quot;)
{
alert(&quot;请输入番号&quot;);
loginForm.dept.focus();
return false;
}
}
</script>
<h3> </h3>
<h3>新用户注册</h3>
<hr>
<form name=&quot;loginForm&quot;
method=&quot;post&quot;
action=&quot;RegServlet&quot;
onsubmit=&quot;return checkForm()&quot;>
<table width=&quot;37%&quot;
border=&quot;1&quot;>
<tr>
<td width=&quot;39%&quot;>用户名:</td>
<td width=&quot;61%&quot;><input type=&quot;text&quot;
name=&quot;name&quot;></td>
</tr>
<tr>
<td>密码:</td>
<td><input type=&quot;password&quot;
name=&quot;password&quot;></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type=&quot;text&quot;
name=&quot;affirm&quot;></td>
</tr>
<tr>
<td>番号:</td>
<td><input type=&quot;text&quot;
name=&quot;dept&quot;></td>
</tr>
</table>
<p>
<input type=&quot;submit&quot;
name=&quot;Submit&quot;
value=&quot;提交&quot;
onclick=&quot;checkForm()&quot;></td>

<input type=&quot;reset&quot;
name=&quot;reset&quot;
value=&quot;重置&quot;></td>

</form>
</center>
</body>
</html>
 
jxa,谢谢,搞定了.
希望多多观注我啊.
 
接受答案了.
 
顶部