Solved

Get selected value of RadioButtonList using JQuery

Posted on 2012-12-31
4
432 Views
Last Modified: 2012-12-31
The function below works fine.  But I was curious as to how to use 'this' with the input:checked selector to find the value of the checked button.  I've tried different formats but haven't hit on the right one. i.e. $('this input:checked').val()

$(function () {
    $('#<%=rblExistingDamage.ClientID%>').click(function () {
        if ($('#<%=rblExistingDamage.ClientID%> input:checked').val() == 'true') {
             $('#<%=rowExistingDamage.ClientID%>').show();
         } else {
            $('#<%=rowExistingDamage.ClientID%>').hide();
        }
    });
});

Open in new window

0
Comment
Question by:jeffhodgeson
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38733071
replace : $('#<%=rblExistingDamage.ClientID%> input:checked')
by : $('input:checked', this)

or

replace : $('#<%=rblExistingDamage.ClientID%> input:checked')
by : $(this).find('input:checked')
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38733077
or replace :
    $('#<%=rblExistingDamage.ClientID%>').click(function () {
        if ($('#<%=rblExistingDamage.ClientID%> input:checked').val() == 'true') {
             $('#<%=rowExistingDamage.ClientID%>').show();
         } else {
            $('#<%=rowExistingDamage.ClientID%>').hide();
        }
    });

Open in new window

by :
    $(":radio", '#<%=rblExistingDamage.ClientID%>').change(function () {
        if ($(this).is(":checked") && $(this).val() == 'true') {
             $('#<%=rowExistingDamage.ClientID%>').show();
         } else {
            $('#<%=rowExistingDamage.ClientID%>').hide();
        }
    });

Open in new window

0
 

Author Closing Comment

by:jeffhodgeson
ID: 38733444
Thanks, just what I was looking for.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38733451
you're welcome
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question