How to check checkbox in jQuery

Posted by Karthime under jQuery on 5/14/2012 | Points: 10 | Views : 1264 | Status : [Member] | Replies : 1
Hi i'm using jQuery in my asp.net mvc application, in this i have created some checkboxes like
$("#dvModules").append('<span>&lt;input type="checkbox" id=Module_' + jsModulesData[ctr].Code + ' name="' + jsModulesData[ctr].Name + '" value="' + jsModulesData[ctr].Code + '"> ' + jsModulesData[ctr].Name + '</span><br/>');

i checked some of them and stored its values in database, when i enter it to this page again, i got the values from the database, but i could not check the corresponding checkboxes with their values my code is below:

var arrModuleIDs = SelectedModuleIDs.split(',');
$(document).ready(function () {
SelectedModuleIDs = '@ViewBag.SelectedModuleIDs';
var arrModuleIDs = SelectedModuleIDs.split(',');
for (var i = 0; i < arrModuleIDs.length; i++) {
$("#Module_" + arrModuleIDs[i] + "").attr('checked', true);
//Here the arrmoduleIDs is the values from database.
}
here the loop is performing well but the checkbox is not checked,
can anyone help me to resolve this.

A.Karthi


Responses

Posted by: Sabarimahesh on: 5/14/2012 [Member] Bronze | Points: 25

Up
0
Down
function countChecked() {
var n = $("input:checked").length;
$("div").text(n + (n != 1 ? " is" : " are") + " checked!");
}
countChecked();
$(":checkbox").click(countChecked);
</script>

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response