I have checkbox input fields that are added to DOM dynamically.
I want to get all checked and unchecked values as mentioned here.
Initially I have one input checkbox field, with a plus button.
On clicking the button new checkbox fields with the same name are added dynamically.
HTML:
<input type="checkbox" name="lead_check[]">
Javascript:
$('#includes').click(function(e)
{
e.preventDefault();
$('#include-fields').append('<div class="holder-includes"><a href="#" class="remove-includes"><i class="fa fa-trash-o pull-right"></i></a>' +
'<select name="team[]" class="form-control team">'+
'<input type="checkbox" name="lead_check[]"></div>');
var items = "";
$.post("teamFetch", function(data)
{
$.each(data,function(index,item)
{
items+="<option value='"+item.id+"'>"+item.title+"</option>";
});
$(".team:last").html(items);
}, "json");
});
So lets say:
box1 [.] <-- initially
box2 [] <-- added dynamically later
box2 [.] <-- added " "
Now let's say I check box1 and box2. Then the lead_check[] array should be like
[lead_check] => Array ( [0] => on [1] => off|NULL [2] => on ).
But instead, I am getting only checked values in lead_check[]
array.
[lead_check] => Array ( [0] => on [1] => on ).
I tried adding hidden input fields too. But they didn't help either.
How do I achieve desired output in case of dynamically generated checkbox input fields.
Any help is very much appreciated. Thanks.