Javascript How to get read Asp Radio Button List Selected Value Selected Text onclick Event C# VB.Net

Using Javascript to get the asp Radio Button List Selected Value or Selected Text is not an easy job like other C#/VB.Net objects. To get the Selected Value from asp Radio Button List using Javascript onclick event you have to iterate through all the Radio Buttons in that set and then read the value for checked item. In this post I will try to give you a complete example on how we can read Selected Value or Selected Text from Asp RadioButtonList using Javascript onclick event of a C#/VB.Net Button control.


To do the Example Add the below RadioButtonList:

<b>Javascript onclick Event To Read or Get Asp Radio Button List SelectedValue SelectedText:</b>
<hr />

<asp:RadioButtonList ID="Aspradiobuttonlist" runat="Server" RepeatDirection="vertical" onclick="GetRadioButtonSelectedValue();">
    <asp:ListItem Text="Cosmetics" Value="1" Selected="True"></asp:ListItem>
    <asp:ListItem Text="Perfume" Value="2"></asp:ListItem>
    <asp:ListItem Text="Beauty Soap" Value="3"></asp:ListItem>
    <asp:ListItem Text="Sunglasses" Value="4"></asp:ListItem>

<br />
<asp:Label runat="server" ID="lblAspradiobuttonValue"></asp:Label>

Javascript Function to get Asp Radio Button List Selected Value:

<script type="text/javascript">
    function GetRadioButtonSelectedValue() {
        var AspRadio = document.getElementById('<%= Aspradiobuttonlist.ClientID %>');
        var AspRadio_ListItem = document.getElementsByTagName('input');
        for (var i = 0; i < AspRadio_ListItem.length; i++) {

            if (AspRadio_ListItem[i].checked) {
                var lblAspradiobuttonValue = document.getElementById('<%= lblAspradiobuttonValue.ClientID %>');

                lblAspradiobuttonValue.innerHTML = '<b>Selected Value:</b> ' + AspRadio_ListItem[i].value + '<br/>';
                lblAspradiobuttonValue.innerHTML += '<b>Selected Text:</b> ' + AspRadio_ListItem[i].parentNode.getElementsByTagName('label')[0].innerHTML;
            } //end if

        } // end for

    } //end function

Note: All codes are same for both C# & VB.Net.

Script tested for below browsers:
1. Internet Explorer
2. Mozilla Firefox
3. Opera
4. Google Chrome

Download Code Example C#        Download Code Example VB.Net

One thought on “Javascript How to get read Asp Radio Button List Selected Value Selected Text onclick Event C# VB.Net

  • March 5, 2015 at 3:14 pm

    var AspRadio = document.getElementById(\’\’); var AspRadio_ListItem = document.getElementsByTagName(\’input\’); Just a note here. I have a page that is much more crowded with inputs tags that this example. Your code worked great if you make the change for the ASPRadio_ListItem variable. Instead of using document.getElementsByTagName(\’input\’) use AspRadio.getElementsByTagName(\’input\’) Great code though, got me out of a jam here.


Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code