Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  46] [ 1]  / answers: 1 / hits: 16365  / 12 Years ago, tue, july 17, 2012, 12:00:00

Have a form using multiple checkboxes with a class of 'test' (only one of which can be checked however similar to using radio buttons - not my idea btw!).



When the form is submitted I want to get the value of the checkbox that is checked and store it in a variable - can anyone help here?



Cheers!



Chris


More From » jquery

 Answers
25
$(form).submit(function() {
var aVariable = $('input.test[type=checkbox]:checked', this).val();
});


.val() returns undefined if called on an empty jQuery object, which would be the case here if no checkboxes are checked.


[#84224] Sunday, July 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marint

Total Points: 550
Total Questions: 105
Total Answers: 124

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
marint questions
;