Html 表格有效性难度
我在这个JSP页面中应用了验证。如果我将用户名/密码保留为空,系统将提示我输入这些to字段,但问题是,在我在验证提示中按OK后,页面将转到2_control.jsp。我希望只有在验证工作正常时,页面才会转到下一页,否则不会转到下一页。plz hlp。我应该做什么更改 这是我的密码:Html 表格有效性难度,html,jsp,Html,Jsp,我在这个JSP页面中应用了验证。如果我将用户名/密码保留为空,系统将提示我输入这些to字段,但问题是,在我在验证提示中按OK后,页面将转到2_control.jsp。我希望只有在验证工作正常时,页面才会转到下一页,否则不会转到下一页。plz hlp。我应该做什么更改 这是我的密码: <html> <head> <script> function validLogin(){ if (document.form.userName.value == ""){ ale
<html>
<head>
<script>
function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
document.loginform.userName.focus();
return false;
}
if (document.form.password.value == ""){
alert ( "Please enter password." );
document.userform.password.focus();
return false;
}
alert ( "Welcome User" );
return true;
}
</script>
</head>
<body>
<form name="form" method="post" action="2_control.jsp" onsubmit="return validLogin();">
<table width="250px" border=0 style="background-color:ffeeff;">
<tr><td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center">User Login</td>
</tr>
<tr><td colspan=2> </td>
</tr>
<tr><td style="font-size:12pt;" align="center">Login Name:</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr><td style="font-size:12pt;" align="center">Password:</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
函数validLogin(){
如果(document.form.userName.value==“”){
警报(“请输入登录名”);
document.loginform.userName.focus();
返回false;
}
如果(document.form.password.value==“”){
警报(“请输入密码”);
document.userform.password.focus();
返回false;
}
警报(“欢迎用户”);
返回true;
}
用户登录
登录名:
密码:
更改document.userform.password.focus()
todocument.form.userName.focus()代码>
当您关注文本框时,仅更改表单名称。。userform错误,因此验证无效。
<script>
function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
document.form.userName.focus();
return false;
}
else if (document.form.password.value == ""){
alert ( "Please enter password." );
document.form.password.focus();
return false;
}
}
</script>
函数validLogin(){
如果(document.form.userName.value==“”){
警报(“请输入登录名”);
document.form.userName.focus();
返回false;
}
else if(document.form.password.value==“”){
警报(“请输入密码”);
document.form.password.focus();
返回false;
}
}
替换此脚本标记。。。
你在写表单名称时犯了一个小错误