Link to home
Create AccountLog in
Avatar of techques
techques

asked on

How to get radiobuttonlist selected value in aspx?

Hi

I need to get the selected value of a radio button list in aspx by javascript.

But it is undefined. I tried ctl01_op too as I saw the id changed to it in html.
function cald() {
var radioList = document.getElementsByName("op");
            for( var i=0; i < radioList.length; ++i)
            {
               if( radioList[i].checked)
              {
                   alert("Checked item: " + radioList[i].value)
              }
            }
}
 
 
<asp:RadioButtonList Runat="server" ID="op" name="op" RepeatDirection="Horizontal" TextAlign="Left" onchange='cald()'>
<asp:ListItem Value="*" Selected="true">*</asp:ListItem>
<asp:ListItem Value="/">/</asp:ListItem>
</asp:RadioButtonList>

Open in new window

Avatar of ajolly
ajolly
Flag of India image

use

var radioList = document.getElementsById(<%=op.ClientID%>);
Avatar of techques
techques

ASKER

the js error said it does not support this property or method.

ASKER CERTIFIED SOLUTION
Avatar of ajolly
ajolly
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
excellent!