JSP注册页面的问题(急!)

function CheckSubmit()
{
if(document.registerform.name.value=="")
{alert("请输入用户名!");
document.registerform.name.focus();
return flase;}
if(document.registerform.password.value=="")
{alert("请输入密码!");
document.registerform.password.focus();
return flase;}
return TRUE;
}

</script>
</head>

<body>
<div align="center">
<p class="STYLE2 STYLE3">请如实填写下面的注册申请单(*为必填项)</p>
<hr width="800" size="0" />

<form name="registerform" id="form1" method="post" action="register-1.jsp">
<table width="343" border="0">
<tr>
<td><div align="center">用户名:</div></td>
<td><input name="name" type="text" class="input1" size="20" />
<span class="style1">*</span></td>
</tr>
<tr>

<td><div align="center">密   码:</div></td>
<td><input name="password" type="password" class="input1" size="20" />
<span class="style1">*</span></td>
</tr>
</table>

<hr width="800" size="0" />
<table width="294" border="0">
<tr>
<td width="147"><input name="Submit" type="submit" class="button1" value="注册" onclick="return CheckSubmit();"/></td>
<td width="137"><input name="Submit2" type="reset" class="button1" value="清除" /></td>
</tr>
</table></form>
</div>
<tr>

第1个回答  2010-05-12
<input name="Submit" type="submit" class="button1" value="注册" onclick="return CheckSubmit();"/>
你这样写,验证通不通过都会提交。因为按钮是submit类型的。

1、先将按钮改成button类型的。
<input name="Submit" type="button" class="button1" value="注册" onclick="CheckSubmit();"/>
2、在js的CheckSubmit()方法中提交表单。
function CheckSubmit()
{
if(document.registerform.name.value=="")
{alert("请输入用户名!");
document.registerform.name.focus();}
else if(document.registerform.password.value=="")
{alert("请输入密码!");
document.registerform.password.focus();}
else{document.registerform.submit();}
}本回答被提问者采纳
第2个回答  2010-05-12
onsubmit="return CheckSubmit();加到form标签里面
第3个回答  2010-05-12
你说清你要解决的是什么问题,那里出问题了
相似回答