4

Possible Duplicate:
How to retrieve checkboxes 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 on submit I need to get the value of checked 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 value "submit".

Community
  • 1
  • 1
Leo Lex
  • 43
  • 3
  • this should in this case point to button for form submit, or to be precise this = $('#button_submit_vote'). $('.vote_answers').val() perhaps is what you are looking for – Puppet Master 3010 Jan 27 '13 at 19:08

2 Answers2

5

That's because this refers to button_submit_vote element, you can :checked selector:

var id = $('.vote_answers:checked').val();
Ram
  • 143,282
  • 16
  • 168
  • 197
1

You haven't been that far:
$('.vote_answers:checked').val()

Sven Kannenberg
  • 859
  • 2
  • 10
  • 20