Solved

how to retrieve value of radio button sets by class

Posted on 2011-09-15
4
258 Views
Last Modified: 2012-05-12
I have a series of radio buttons with class="weight"
I thought I could get the current selected value with this:

$('.weight radio:checked').val()

...but does not seem to work. I also have them with a name="weight" so if its easier to do this by name, that would be an OK solution as well.

Thank you!
0
Comment
Question by:bbdesign
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36544860
it should be

$('input[type='radio'].weight:checked').val()

or just

$('.weight:checked').val()
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36544869
to fetch by name


$('input[name='weight']:checked').val()
0
 

Author Comment

by:bbdesign
ID: 36544972
Excellent, thanks.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36544973
just add << : >> and no space before radio : $(".weight:radio:checked").val()
test page : http://jsfiddle.net/dahVc/

$(".weight:radio").change(function() {
    //alert( $(this).val() );
    alert( $(".weight:radio:checked").val() );
})

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

803 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