关于一个函数同时验证多个表单问题!

cullstar 2003-07-21 06:54:53
我有一个页面里,有多个FORM的TEXT框需要判断是否为数字,现在我知道怎么判断数字,但我做提交时出错了,我写出来吧
<script language="javascript">
function checkNum(str){
if(!/\D/.test(str))
form.submit(); //此句出错,因为必须指定一个具体的FORM名称,而我需要在不同时候提交不同的FORM,怎么办?
else
alert("请输入数字!");
}
</script>
...全文
155 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2003-07-22
  • 打赏
  • 举报
回复
噢,手快了
....
<input type=button value=submit onclick="javascript:checkNum(this.form.text2.value,this.form)">
</form>
是,不是.
fzel_net 2003-07-22
  • 打赏
  • 举报
回复
<script>
function checkNum(str,form){
if(!/\D/.test(str))
form.submit();
else
alert("请输入数字!");
}
</script>

<form name=ex method=post action="">
<input name=text1 type=text size="20">
<input type=button value=button1 name=button1 onclick="checkNum(this.form.text1.value,this.form)">
</form>

<form name=qq method=post action="">
<input name=text2 type=text size="20" >
<input type=button value=button2 name=button2 onclick="checkNum(this.form.text2.value,this.form)">
</form>
niuanxin 2003-07-22
  • 打赏
  • 举报
回复
再加一个参数吧!能解决问题就行,别太强求……

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<form action="" method="get" name="form1">
<input name="noname" type="text" onBlur="checkNum(this.value,'form1')">
</form>
</body>
</html>
<script language="javascript">
function checkNum(str,formname)
{
if(!/\D/.test(str)){
(eval(formname)).submit();
}
else{
alert("请输入数字!");
}
}
</script>

cullstar 2003-07-22
  • 打赏
  • 举报
回复
xuzuning(唠叨) 的方法,第一个添数字可以提交,但再在第二个框里添数字就会出现脚本错误!
请问那位高手可以解决啊!!!
xuzuning 2003-07-22
  • 打赏
  • 举报
回复
<script language="javascript">
function checkNum(str,form){
if(!/\D/.test(str))
form.submit();
else
alert("请输入数字!");
}
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name=form1 method=post action="post.asp">
<input name= text1 type=text>
<input type=button value=button1 name=button1 onclick="javascript:checkNum(this.form.text1.value,this.form)">
</form>

<form name=form2 method=post action="post.asp">
<input name= text2 type=text >
<input type=button value=submit onclick="javascript:checkNum(this.form.text2.value.this.form)">
</form>

fainting 2003-07-22
  • 打赏
  • 举报
回复
以上都不对唉,代吗给出,你们自已试试:
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
function checkNum(str){
if(!/\D/.test(str))
eval(form+".submit()");
else
alert("请输入数字!");
}
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name=form1 method=post action="post.asp">
<input name= text1 type=text>
<input type=button value=button1 name=button1 onclick="javascript:checkNum(form1.text1.value)">
</form>

<form name=form2 method=post action="post.asp">
<input name= text2 type=text >
<input type=button value=submit onclick="javascript:checkNum(form2.text2.value)">
</form>

</body>
</html>
全息宇宙 2003-07-21
  • 打赏
  • 举报
回复
<script language="javascript">
function checkNum(str){
if(!/\D/.test(str))
eval(form+".submit()");
else
alert("请输入数字!");
}
</script>
形印声传 2003-07-21
  • 打赏
  • 举报
回复
form.submit();----->this.submit();

87,988

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧