JS判断RadioButtonList是否有选中项

提交表单之前对RadioButtonList控件的选中项进行判断:

方法一:

 <script type="text/javascript">
function checkra()
        {
             var rbltable = document.getElementById("rbType");
             var rbs = rbltable.getElementsByTagName("Input");
             var result = false;
             for (var i = 0; i < rbs.length; i++) {
                 if (rbs[i].checked) {
                     result = true;
                     break;                 }
            }
           
            return result;
        }
   </script>

方法二:

<script type="text/javascript">
   function checkvalue()
{
    var condITion='';
for (var i=0 ; i <form1.elements.length;i++)
{
if (form1.elements[i].type=="radio")
{
if (form1.elements[i].checked )
    {
    condITion=true;
    break;
    }
}
}
    if(!condITion)
    {
        alert("请选择咨询类型");
        return false;
    }

</script>

posted on 2010-04-21 18:10  AlexGeng  阅读(4883)  评论(0编辑  收藏  举报

导航