Using jQuery, how can I get the value of checkboxes?

Possible duplicate:
How to get checkbox values ​​in jQuery

I have the following form:

<form action="index.php"> <div class="answer"><input type="radio" name="vote_answers" value="3615736&1047558" class="vote_answers"> 1</div> <div class="answer"><input type="radio" name="vote_answers" value="3615736&1121626" class="vote_answers"> 2</div> <div class="answer"><input type="radio" name="vote_answers" value="3615736&9910782" class="vote_answers"> 3</div> <input type="submit" name="submit" id="button_submit_vote" value="submit"> </form> 

When I click send , I need to set checkboxes with checkboxes

This is my code:

 $('#button_submit_vote').on('click',function() { if($('.vote_answers').is(':checked')){var id=$(this).val();} alert(id); }); 

Instead of the checkbox value, I get the value "submit".

+4
source share
2 answers

That, since this refers to the button_submit_vote element, you can :checked selector:

 var id = $('.vote_answers:checked').val(); 
+4
source

You are not so far:
$('.vote_answers:checked').val()

+1
source

All Articles