Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Check any value of RadioButtonList
JavaScript
<script>
document.getElementById("<%=rblTitle.ClientID %>").selected = document.getElementById("<%= hfTITLE.ClientID %>").value;
</script>

ASP.NET
<asp:RadioButtonList ID="rblTitle" runat="server" RepeatDirection="Horizontal">
                                   <asp:ListItem Text="Mr" Value="Mr"></asp:ListItem>
                                   <asp:ListItem Text="Mrs" Value="Mrs"></asp:ListItem>
                                   <asp:ListItem Text="Ms" Value="Ms"></asp:ListItem>
                               </asp:RadioButtonList>



How to select or check by javascript
Posted
Comments
You need to get the selected radio's value, right?
For example - if I select "Mr.", then you want the value "Mr." using javaScript.
If I am wrong, then correct me.
Member-515487 5-Feb-13 4:11am    
yes can u suggest how?
Please check my answer.

I would suggest you to go for jQuery, in which it is be very simple.

Steps to execute any jQuery code
1. Download the jQuery file from Official Website[^].
2. Place inside your project and include in your html (inside head section) like below.
XML
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>


Solution for the asked question
The code provided by you for RadioButtonList will be rendered in browser like below.
XML
<table id="rblTitle">
    <tbody>
        <tr>
            <td>
                <input type="radio" value="Mr" name="rblTitle" id="rblTitle_0">
                <label for="rblTitle_0">Mr</label>
            </td>
            <td>
                <input type="radio" value="Mrs" name="rblTitle" id="rblTitle_1">
                <label for="rblTitle_1">Mrs</label>
            </td>
            <td>
                <input type="radio" value="Ms" name="rblTitle" id="rblTitle_2">
                <label for="rblTitle_2">Ms</label>
            </td>
        </tr>
    </tbody>
</table>

Now you have to work on this code in client-side using jQuery.

So, to get the selected value of radio button, use the below javaScript code in your page.
XML
<script type="text/javascript">
     $(document).ready(function () {
         // Get the Radio Buttons.
         var rblTitle = $('#rblTitle').find('input:radio');

         rblTitle.click(function () {
             // Get the selected value
             alert($(this).val());
         });
     });
</script>

The selected value will be shown in an alert.

Demo
Selected value of RadioButton inside RadioButtonList[^].

Thanks...
 
Share this answer
 
v3
Try this
JavaScript
document.getElementById('yourRadioButtonId').checked = true;

Hope this help
 
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