I have some checkbox on a dialog box and i am checking data availability from database.If checkbox value is 1 then it should be checked and if not 1 then should not be checked.
I have multiple list for which this dialog box is opening and on every opening checkbox has to be reset.
Now my problem is when i have value in database it showing checked its Ok and when i am not geting value 1 then it clear checked. also ok but now i again opened dialog for having value 1 in this case checkbox is not checked but in html code it have an attribute checked. my code is:
if (item.status) {
if (item.cma == '1') {
$('#cma').attr('checked', 'checked');
} else {
$('#cma').removeAttr('checked');
}
} else {
$('#cma').removeAttr('checked');
}
problem occurring when script going through item.status=false
case. I can't CTR+F5
because its is in dialog box. Please help me. Your help would be appreciated.
Change the checked value with prop instead of attr:
$('#cma').prop('checked',true);
Documentation: http://api.jquery.com/prop/#prop-propertyName-value
You can do this
if (item.status) {
if (item.cma == '1') {
$('#cma').attr('checked', true);
} else {
$('#cma').attr('checked',false);
}
} else {
$('#cma').attr('checked',false);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.