Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


How to get the radiobutton list selected value in javascript.could any one suggest me


Regards,
Rahul.
Posted
Comments
Sergey Alexandrovich Kryukov 22-Dec-13 22:19pm    
And what, just reading the documentation is not an option?
—SA

The input element "radio" has the property checked to be used for this purpose:
http://www.w3schools.com/jsref/dom_obj_radio.asp[^],
http://www.w3schools.com/jsref/prop_radio_checked.asp[^].

—SA
 
Share this answer
 
Comments
Correct advice. 5+
Sergey Alexandrovich Kryukov 23-Dec-13 0:42am    
Thank you, Tadit.
—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Dec-13 22:21pm    
We were writing the answers at the same time. Same thing, a 5.
—SA
Thanks a lot Sergey. :)
Hi , Try this practical example..

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
   
    <script type="text/javascript">

        var alertradio = function () {
            var rb = document.getElementById("<%=rb.ClientID%>");
            var inputs = rb.getElementsByTagName('input');
            var flag = false;
            var selected;
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].checked) {
                    selected = inputs[i];
                    flag = true;
                    break;
                }
            }
            if (flag)
                alert(selected.value);
            else
                alert('Please select an option');

        }




    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:RadioButtonList ID="rb" runat="server">
        <asp:ListItem Text="one" />
        <asp:ListItem Text="two" />
        <asp:ListItem Text="three" />
        <asp:ListItem Text="four" />
    </asp:RadioButtonList>
    <asp:Button ID="btn" runat="server" Text="Test" OnClientClick="alertradio(); return false;" />
    </form>
</body>
</html>
 
Share this answer
 
<code><code><code><code>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900