How do I get the SelectedValue from a RadioButtonList using javascript

P

pierre

Can anyone tell me how to get the SelectedValue from a ASP.net
RadioButtonList, using javavscript.

Here is my code:

<ASP:RADIOBUTTONLIST id="optOption" runat="server"
ONCLICK="javascript:alert(docu­ment.all.optOption.selectedIte­m);"></ASP:RADIOBUTTONLIST>


This is not working. I am getting an error saying that
'document.all.optOption.select­edItem is null or not an object'.

Thanks in advance,
Pierre
 
N

nandha

Hi,

Please remove inline javascript code.
<ASP:RADIOBUTTONLIST id="optOption"
runat="server"></ASP:RADIOBUTTONLIST>

Add the following code in the code behind file.

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

optOption.Attributes.Add("OnClick", "alert(" &
optOption.ClientID.ToString & ".value)")
End Sub

Regards,
nandha.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top