How can I determine the SelectedValue of a RadioButtonList in JavaScript?

前端 未结 13 2090
一生所求
一生所求 2020-12-16 15:20

I have an ASP.NET web page with a databound RadioButtonList. I do not know how many radio buttons will be rendered at design time. I need to determine the SelectedValue on

相关标签:
13条回答
  • 2020-12-16 16:04

    ASP.NET renders a table and a bunch of other mark-up around the actual radio inputs. The following should work:-

     var list = document.getElementById("radios"); //Client ID of the radiolist
     var inputs = list.getElementsByTagName("input");
     var selected;
     for (var i = 0; i < inputs.length; i++) {
          if (inputs[i].checked) {
              selected = inputs[i];
              break;
           }
      }
      if (selected) {
           alert(selected.value);
      }
    
    0 讨论(0)
提交回复
热议问题