jsp中如何判断提交表单内的内容是否为空

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单元素的值是否为空了……

posted @ 2020-09-17 15:49  程序员宝典  阅读(985)  评论(0编辑  收藏  举报