I am creating some checkboxes in a div using these line of code:
for(j=0;j<allActivities.length;j++){
$('#activity_checkboxlist').append('<input type="checkbox" id="checkbox"'+j+' value="'+allActivities[j].activitynumber+'"/>'+allActivities[j].activityname+'<br>');
}
Where activity_checkboxlist is a div. Now i am checking if a check box is checked then put its value in an array. I am doing that using this code:
var selectedareas = new Array();
for (i = 0; i < allActivities.length; i++) {
var chkval = $('#checkbox' + i + ':checked').val();
alert(chkval);
if (chkval !== undefined) {
selectedareas.push(chkval);
}
}
That alert always shows that chkval's value is undefined. even i check those checkboxes. Is there any wrong with my code? Thanks in advance.
$('#activity_checkboxlist :checkbox:checked').each(function(){});.var chkval = $(this).val()instead to get the checkbox's value, orselectedareas.push($(this).val());.