Chinaunix
标题:
关于表单验证的疑问
[打印本页]
作者:
95518
时间:
2007-11-21 12:19
标题:
关于表单验证的疑问
一asp文件,源码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<title> Untitled Document </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<script language= "javascript ">
<!--
function chkform() {
if (form1.hinttext.value== ' ') {
alert( '请填写提示信息 ');
Login.ywcode.focus();
return false;
}
return ture;
}
//-->
</SCRIPT>
</head>
<body>
<form name= "form1 " method= "post " action= "chx.asp ">
<table width= "600 " align= "center " cellspacing= "1 " bgcolor= "#0066FF ">
<tr bgcolor= "#CCffff ">
<td height= "28 " colspan= "4 "> <div align= "center ">
<font size=2> 维护 </font> </div> </td>
</tr>
<tr bgcolor= "#FFFFFF ">
<td height= "28 "> <div align= "right "> <font size=2> <strong> 业务代码 </strong> : </font> </div> </td>
<td colspan= "3 "> <input type= "text " name= "ywcode " size= '16 ' maxlength= '16 '> </td>
</tr>
<tr bgcolor= "#FFFFFF ">
<td height= "28 "> <div align= "right "> <font size=2> <strong> 提示信息 </strong> : </font> </div> </td>
<td colspan= "3 "> <textarea name= "hinttext "> </textarea> </td>
</tr>
<tr bgcolor= "#FFFFFF ">
<td height= "30 " colspan= "4 "> <div align= "center ">
<input type= "submit " name= "Submit " value= "录入 " onclick= "return chkform(); ">
</div> </td>
</tr>
</table>
</form>
</body>
</html>
原意为:若提示信息没输入内容,则弹出提示信息,并让重新录入。
但实际运行效果是若提示信息没输入内容,弹出警告信息后,在警告信息界面点击确定后,程序仍继续执行了
action= "chx.asp "中chx.asp页面的内容。请问是何原因呀?该如何解决呢?谢谢
作者:
nepalese
时间:
2007-11-29 14:48
标题:
回复 #1 95518 的帖子
用button,不要用submit....
作者:
westdo
时间:
2007-11-30 18:36
应该把
<form name= "form1 " method= "post " action= "chx.asp ">
改成
<form name= "form1 " method= "post " action= "chx.asp " onsubmit="return chkform(); ">
submit里的onclick去掉
作者:
wangcn
时间:
2007-12-09 17:25
把javascript里的Login换成form1,return值写错了。
在标签的属性值的末尾不要加空格。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2