Click here to Skip to main content
12,405,653 members (61,836 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
How to Check any value of RadioButtonList
<script>
document.getElementById("<%=rblTitle.ClientID %>").selected = document.getElementById("<%= hfTITLE.ClientID %>").value;
</script>
<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 4-Feb-13 22:06pm
Comments
Tadit Dash 5-Feb-13 4:10am
   
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?
Tadit Dash 6-Feb-13 5:43am
   
Please check my answer.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
<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.
<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.
<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...
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this
document.getElementById('yourRadioButtonId').checked = true;
Hope this help
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100