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
  • 78,589
  • 36
  • 144
  • 183
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
  • 146,340
  • 25
  • 209
  • 204
0

try like this:

$(function(){
  $('.ami').click(function(){
    var val = [];
    $(':checkbox:checked').each(function(i){
      val[i] = $(this).val();
    });
  });
});
Amrendra
  • 2,019
  • 2
  • 18
  • 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
  • 384,651
  • 66
  • 527
  • 531
0

Try this way,

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