0

there is dynamic checkbox like this :

<input type="checkbox" checked="checked" value="1" name="user_mail_check[]" class="ami">
<input type="checkbox" checked="checked" value="2" name="user_mail_check[]" class="ami">
<input type="checkbox"  value="3" name="user_mail_check[]" class="ami">
<input type="checkbox" checked="checked" value="4" name="user_mail_check[]" class="ami">
<input type="checkbox"  value="5" name="user_mail_check[]" class="ami">

How can I get value of each checked checkbox.

I used

$('.ami').is(":checked").value();

but it did not work.

hjpotter92
  • 75,209
  • 33
  • 136
  • 171
Code Baba
  • 118
  • 1
  • 2
  • 9

4 Answers4

3

There is no value() function use val() You can use each to iterate through the elements with class ami,

$('.ami:checked').each(function(){
  alert($(this).val());
});
Adil
  • 143,427
  • 25
  • 201
  • 198
0

try like this:

$(function(){
  $('.ami').click(function(){
    var val = [];
    $(':checkbox:checked').each(function(i){
      val[i] = $(this).val();
    });
  });
});
Amrendra
  • 2,009
  • 2
  • 17
  • 36
0

This will give all the checked values in an array.

var values = $('.ami').map(function(i,el){
    if($(el).is(':checked')){
        return $(el).val()
    }
}).get();
Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
0

Try this way,

$('.ami').each(function(){
  if($(this).is(':checked')){ 
    $(this).val(); // get checked value
  }
});
Swarne27
  • 5,411
  • 7
  • 25
  • 40