<form action="123.asp" method="post" name="form1">
<input type="text" name="username" size="14" >
<input type="password" name="pwd" size=9 />
<input type="submit" name="Submit" value="登陆" />
</form>
我希望对表单中输入的数据进行判断,如果输入的数据为空,则弹框提示不能为空,并且表单不提交,不为空的时候,就提交表单,代码要怎么写呢
<script>
function nclick()
{
if(document.form1.username.value=="")
{
alert("用户名不能为空!")
return false;
}
if(document.form1.pwd.value=="")
{
alert("密码不能为空!")
return false;
}
return true;
}
</script>
<form action="123.asp" method="post" name="form1" onsubmit="return nclick()">
<input type="text" name="username" size="14" >
<input type="password" name="pwd" size=9 />
<input type="submit" name="Submit" value="登陆" />
</form>
<form action="123.asp" method="post" name="form1" onsubmit="check()">
<input type="text" name="username" size="14" >
<input type="password" name="pwd" size=9 />
<input type="submit" name="Submit" value="登陆" />
</form>
<script language="vbscript">
sub check()
if form1.username.value="" Then
MyVar = MsgBox ("请输入用户名",48,"系统错误")
window.event.returnvalue=false
else if form1.pwd.value="" Then
MyVar = MsgBox ("请输入密码",48,"系统错误")
window.event.returnvalue=false
End If
End If
End sub</script>
<script language="javascript">
function checkform(theform)
{
if (theform.username.value==""){
theform.username.focus();
alert ("用户名不能为空,请重新输入!");
return false;
}
if (theform.password.value==""){
theform.password.focus();
alert ("密码不能为空,请重新输入!");
return false;
}
}
</script>