Hi i'm using jQuery in my asp.net mvc application, in this i have created some checkboxes like
$("#dvModules").append('<input type="checkbox" id=Module_' + jsModulesData[ctr].Code + ' name="' + jsModulesData[ctr].Name + '" value="' + jsModulesData[ctr].Code + '"> ' + jsModulesData[ctr].Name + '
');
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.
"#Module_" + arrModuleIDs[i]generate a valid selector, i.e. is it selecting an element? Do some basic debugging... since we don't have an example of the value of the selector or the HTML, you have to do this on your own. Also try to use.propinstead of.attr.attr('checked',true)should be fine. Might be better context around this might help us to help you!