JS判断RadioButtonList是否有选中项

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

方法一:

<script type="text/javascript">

function checkra()

        {

             var rbltable = document.getElementByIdx("rbType");

             var rbs = rbltable.getElementsByTagName_r("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>

 

你可能感兴趣的:(RadioButton)