验证广播组 [英] Validate radio group

查看:79
本文介绍了验证广播组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此脚本,我想验证单选组,并且当出现错误消息时,我希望光标进入错误的单选输入.相反,它会重置表格.您能告诉我我的代码出了什么问题吗?

Using this script I want to validate a radio group and when the error message comes up I want the cursor to go the radio input that is in error. Instead it resets the form. Could you tell me where my code has gone wrong?

theForm.Cover_Style.focus();


是我添加的内容.



is what i added.


var radioSelected = false;
for (i = 0;  i < theForm.Cover_Style.length;  i++)
   {
   if (theForm.Cover_Style[i].checked)
      radioSelected = true;
   }
if (!radioSelected)
   {
   alert("Please select a \"Cover Style (Soft Cover or Hard Cover)\.");
   theForm.Cover_Style.focus();
   return (false);
   }



[edit]主题-尝试简要描述您的问题. 初学者需要帮助"并不能帮助我们在花时间打开链接之前决定是否知道您的问题.
添加代码块以提高可读性-OriginalGriff [/edit]



[edit]Subject - Try to describe your problem briefly. "Beginner needs help" doesn''t help us decide if we know about your problem before we take the time to open the link.
Code block add to improve readability - OriginalGriff[/edit]

推荐答案

不要这样做,而是将组中的单选项目设置为选中状态,并需要验证是否没有选中单选按钮将被消除.如果有必要,添加一个单选按钮,显示未选中"或适当的标记,并默认将其选中.
Instead of doing that, set a radio item in the group as selected and the need to validate whether or not a radio button is checked is eliminated. If you have to, add a radio button that reads "Not selected", or somethig appropriate, and select it by default.


这篇关于验证广播组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆