function validate(){if (document.myform.username.value==""){alert("用戶名不能為空bai.");
document.myform.username.focus();
return false ;}if (document.myform.userpass.value==""){alert("密碼不能為空.");
document.myform.userpass.focus();
return false ;}
return true;}</script
jsp頁面代碼:du
<form action="conn.jsp" method="post" name="myform" id="myform"
<table width="44%" border="2" align="center" cellpadding="0" cellspacing="0"<tr<td width="33%"用戶名:</td
<td width="67%"<input type="text" name="username"</td</tr<tr<td密 碼:</td
<td<input type="password" name="userpass"</td</tr</table
<input type="submit" name="Submit" value="提交"</form在form里添加onsubmit="return validate()“,即改成:zhi
這樣就可以驗證所提交表dao單元素的值是否為空了……
