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.

0

4 Answers 4

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()); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

you're selecting all checkboxes, not only the the checked ones
close alert box like : alert($(this).val());
0

try like this:

$(function(){ $('.ami').click(function(){ var val = []; $(':checkbox:checked').each(function(i){ val[i] = $(this).val(); }); }); }); 

Comments

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

Comments

0

Try this way,

$('.ami').each(function(){ if($(this).is(':checked')){ $(this).val(); // get checked value } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.