如何将验证置于单选按钮 [英] How to put validation in radio button

查看:103
本文介绍了如何将验证置于单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在单选按钮中放入验证.
或告诉我是否可以将它们分组.


I want to put validation in radio button.
or tell me if i can make them in a group.

<td width="52%"><input type="radio" id="excellent" name="rate" value="Excellent" /><small>Excellent</small>
<input type="radio" id="good" name="rate" value="Good" /><small>Good</small>
<input type="radio" id="average" name="rate" value="Average" /><small>Average</small>
<input type="radio" id="notgood" name="rate" value="Not Good" /><small>Not Good</small>
<input type="radio" id="poor" name="rate" value="Poor" /><small>Poor</small>
    
i use this it is working but i donot want to put this. if any-other solution beside this then pls let me know.

if (( document.getElementById("good").checked == false ) && (document.getElementById("average").checked == false ) && (document.getElementById("notgood").checked == false ) && ( document.getElementById("poor").checked == false ) && ( document.getElementById("good").checked == false ) ){
        alert ( "Please choose Radio Button!" );
        document.rate.radios[0].focus();
        return false;
    }

Thanks

推荐答案

myOption = -1;
for (i=WebToLeadForm.experience.length-1; i>-1; i--) 
{
    if (WebToLeadForm.experience[i].checked) 
    {
        myOption = i; i = -1;
    }
}
if (myOption == -1) 
{
    alert("You must select a radio button");
    return false;
}


Enhzflep :固定代码标签


Enhzflep: fixed code-tags


这篇关于如何将验证置于单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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