Hello Friends,
I am creating a view using MVC4 where I have to create controls dynamically based on the number of records I am receiving from database. I have two type of controls textbox and checkbox. Textbox value I am setting dynamically whatever I am gettingin my model. But I am stuck while setting checked attribute of checkbox. What I want is if I received feature_flag value Yes then for that row checkbox should be checked else uncheck.
Below is the code I have written:-
function OnSuccessSelectedModuleFeatureList(data) {
var appdata = data.applicationAdmin;
var row = "";
debugger;
$.each(appdata, function (index, item)
{
row += "
" + item.feature_name + " | <input type=\"checkbox\" id=\"Check" + index + "\"> | <input type=\"text\" value=" + item.feature_value + "> |
";
if (item.feature_flag == "Y")
{
var a = 'Check' + index;
$('#Check' + index).attr('checked', 'checked');
// $('#Check' + index).prop('checked', true);
}
else
{
$('#Check' + index).prop('checked', false);
}
});
$('#FlagAutomationModuleSelectedModuleFetures tbody').html(row);
$('#SelectedModuleNameStep2').html(SelectedModuleName)
}
for textboxes it is working but for checkboxes it is not working.
I would be grateful if anybody can help. Please reply if more details are required.
Thanks in advance.