Sunday, 16 July 2017

javascript - How to find out whether the check box is checked or not checked?





I have below code in my jsp.



 I have a bike
I have a car
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?


Answer



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);


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...