表单验证问题

gaoyinfeng 2005-11-28 10:36:30
我对表单作验证时,对<input name="leixin" type="radio" value="consumer"><input type="radio" name="leixin" value="company">作验证,用了<script language="JavaScript">
<!--
function check(form)
{
if(form.leixin.value==""){alert("请选择登陆类型!")}
}
//-->
</script>,
怎么还是验证不了呢?谢谢
...全文
221 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mars_net 2005-11-29
  • 打赏
  • 举报
回复
表单里面应该加上调用的事件啊
onclick="check()"
来调用你写的JavaScript
x1h2w3 2005-11-29
  • 打赏
  • 举报
回复
上面的form.leixin.focus改成form.leixin(0).focus()
x1h2w3 2005-11-29
  • 打赏
  • 举报
回复
汗,不是什么都value的,radio要逐个判断
if(form.leixin(0).checked==false && form.leixin(1).checked==false){alert("请选择登陆类型!");form.leixin.focus;return false;}
gaoyinfeng 2005-11-29
  • 打赏
  • 举报
回复
现在改成这个,name和password都能验证,可就是leixin还是不行,谢谢各位了:
<script language="JavaScript">
<!--
function check(form)
{
if(form.name.value==""){alert("请输入您的注册用户名!");form.name.focus();return(false)}
if(form.password.value==""){alert("请输入您的注册密码!");form.password.focus();return(false)}
if(form.leixin.value==""){alert("请选择登陆类型!");form.leixin.focus();return false;}
}
//-->
</script>

<form name="form" onsubmit="return check(form)" method="post" action="login-error.asp">
<table width="60%" height="137" border="0" cellpadding="0" cellspacing="1" bgcolor="#A7B6D5">
<tr>
<td height="24" background="images/jingjia-topbg.jpg">
<div align="center">竞价平台登陆</div></td>
</tr>
<tr>
<td height="110" bgcolor="#FFFFFF">
<div align="center">

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="14%" height="24"> </td>
<td width="86%" height="24">  用户名称:
<input name="name" type="text" id="name" size="15">
  <font color="#0100F8">没有注册?</font></td>
</tr>
<tr>
<td height="24"> </td>
<td height="24">  用户密码:
<input name="password" type="password" id="password" size="15"></td>
</tr>
<tr>
<td height="24">  </td>
<td height="24">  类型选择:
<input name="leixin" type="radio" value="consumer">
用户  <input name="leixin" type="radio" value="company">
商家</td>
</tr>
<tr>
<td height="32" colspan="2">
<div align="center"></div>
<div align="center">
<input type="submit" name="Submit" value=" 登陆 ">
  
<input type="reset" name="Submit2" value=" 取消 ">
</div></td>
</tr>
</table>
</div></td>
</tr>
</table>
<br>
<br>
<a href="javascript:history.back()"><font color="#0000FF">BACK</font></a>
</form>
lele20100_ 2005-11-29
  • 打赏
  • 举报
回复
你可能没有触发这个函数,用onsubmit()调用你定义的函数,同时本程序还添加了获得焦点的功能,可以更加完善此验证操作
<SCRIPT language=javascript>
function check()
{
if(document.form2.leixin.value=="")
{alert("请选择登陆类型!");
document.form2.leixin.focus();
return false;}
</SCRIPT>
<form name="form2" onSubmit="return check()" action="" method=post>
wucl1213 2005-11-29
  • 打赏
  • 举报
回复
特别注意名字的统一,
asp_m 2005-11-29
  • 打赏
  • 举报
回复
<form action="" method="post" onsubmit="return check(this)"></form>

然后在你的check函数里面这么写
function check(form)
{
if(form.leixin.value=="")
return false;
else
return true;
}
LifeForCode 2005-11-29
  • 打赏
  • 举报
回复
是啊,或者表单的onSubmit事件
还有,你的js函数里面没有return false,白验证了

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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