Reputation: 113
I have an array of checkboxes. If there is a checked checkbox, it will be added into a string of text. Here is my code:
var a = $(this).closest('tr').parent().closest('tr').find('input[type="checkbox"].CheckedArray');
for (var i = 0; i < a.length; i++) {
if (a[i].is(':checked')) {
list= list+ a[i].value + ", ";
}
alert(list);
}
<table id="" class="table">
<tr>
<td>
<div class="form-horizontal form-inline">
<input class="CheckedArray" type="Checkbox" value="' + Id + '" id="CheckedArray" name="CheckedArray" />Select<div class="form-group"><label for="" class="control-label col-sm-1"></label><label for="" class="control-label col-sm-4">PD No: </label><div class="col-sm-3"><input name="PDNo" class="form-control input-sm " id="PDNo" type="text" /></div></div>
</div>
</td>
</tr>
I used checked
as condition but it doesnt show any alert. I dont want to use filter function because i need the iteration value to shows other input.
Upvotes: 0
Views: 2194
Reputation: 815
You got the location for checked checkbox but you will never get the element if you are not using $ sign..
Use the below code and everything will work out.
$(a[I]).prop("checked");
Upvotes: 1
Reputation: 486
Could you use
<script>
$(document).ready(function()
{
$(".CheckedArray").change(function()
{
console.log( $(this).prop("checked"),$(this).attr("id") );
});
});
</script>
<table id="" class="table">
<tr>
<td>
<div class="form-horizontal form-inline">
<input class="CheckedArray" type="Checkbox" value="' + Id + '" id="CheckedArray" name="CheckedArray" />Select<div class="form-group"><label for="" class="control-label col-sm-1"></label><label for="" class="control-label col-sm-4">PD No: </label><div class="col-sm-3"><input name="PDNo" class="form-control input-sm " id="PDNo" type="text" /></div></div>
</div>
</td>
</tr>
Upvotes: 0
Reputation: 66
if ( $( elem ).prop( "checked" ) )
{
\\Code_here
}
Or
if ( $( elem ).is( ":checked" ) )
{
\\Code_here
}
Both will work.Try adding $ sign in your code.
Upvotes: 2