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

前端 未结 13 2162
一生所求
一生所求 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:03

    I always View Source. You will find each radio button item to have a unique id you can work with and iterate through them to figure out which one is Checked.

    Edit: found an example. I have a radio button list rbSearch. This is in an ascx called ReportFilter. In View Source I see

    ReportFilter1_rbSearch_0
    ReportFilter1_rbSearch_1
    ReportFilter1_rbSearch_2
    

    So you can either loop through document.getElementById("ReportFilter1_rbSearch_" + idx ) or have a switch statement, and see which one has .checked = true.

提交回复
热议问题