Solved

how to retrieve value of radio button sets by class

Posted on 2011-09-15
4
255 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now