听说这里高手多,问一问ASP里本页的表单验证

来源:百度知道 编辑:UC知道 时间:2024/06/17 18:53:05
如下一个网页,如何在提交的时候验证:
1.text1不能等于空,且全是数字,否则弹出对话框提示错误
2.test8不能等于空,否则弹出对话框提示对错误

只在本页认证,不需要跳转,点了提交后即跳出对话框.
听说这里高手多,请多多指教.

<html>
<head></head>
<body>
<form action="add.asp" method=post id=form1 name=form1>

<input name="text1" class="txtbox"></td>
<input name="text8" class="txtbox" value="<%=session("fzr")%>" >

<input type="submit" name="Submit" value="确定" class="butt" >
<input type="reset" name="Submit3" value="清除" class="butt" >
</form>

</body>
</html>

分3部来修改你的代码;
1----在text1只能输入数字:
<input name="text1" class="txtbox" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" />
2----编辑函数checkValue():
<SCRIPT language=JavaScript>
function checkValue(){
if(document.form1.text1.value==""){
alert("text1不能空");
form1.text1.focus();
return false;
}
if(document.form1.text8.value==""){
alert("text8不能空");
form1.text8.focus();
return false;
}
}
</script>
可以放在任何位子.
3----调用函数checkValue()
<form action="add.asp" method=post id=form1 name=form1 onsubmit="return checkValue();">在提交表单的同时;
最后大功告成.

<html>
<head>
<SCRIPT language=JavaScript>
function checkform(){
if(document.form1.text1.value==''){
a