-3

I have below code in my jsp.

<input type="checkbox" name="transport" id="bike" value="Bike"> I have a bike
<input type="checkbox" name="transport" id="car" value="Car"> I have a car
<input type="checkbox" name="transport" id="cycle" value="cycle"> I have a cycle

using jQuery I have to get all values whose check box is checked. How can I get the values whose check box is checked?

vaultah
  • 44,105
  • 12
  • 114
  • 143
user1016403
  • 12,151
  • 35
  • 108
  • 137

3 Answers3

2

I'm not too familiar with jQuery, but try this:

var values = [];
$('input[name="transport"]').each(function () {
    if ( $(this).is(':checked') ) {
        values.push( $(this).attr('value') );
    }
});

alert(values);
Joe Simmons
  • 1,828
  • 2
  • 12
  • 9
0

Try this:

$('#bike').is(':checked');
Erik Nijland
  • 1,181
  • 2
  • 9
  • 24
0
$(':checkbox[name=transport]:checked').each(function (i, ele) {
    var value = $(ele).val();
    console.log(value); 
});
s4ty
  • 297
  • 3
  • 7