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

前端 未结 13 2183
一生所求
一生所求 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 15:48

    I would like to add the most straightforward solution to this problem:

    var reasons= document.getElementsByName("<%=RadioButtonList1.UniqueID%>");
    var answer;
    for (var j = 0; j < reasons.length; j++) {
        if (reason[j].checked) {
            answer = reason[j].value;
        }
    }
    

    UniqueID is the property that gave you the name of the inputs inside the control, so you can just check them really easily.

提交回复
热议问题