jquery .prop() on checkbox not working -
currently beating head against wall wondering why can't seem set checked property of checkbox based on the value of variable.
i'm trying make page editable. when user chooses edit page, current values stored in sessionstorage , recalled in order replace changed values original value if user cancels. i've stored original checked values (true or false) in session storage , i'm trying use values populate checked state on cancel (this occurs in each loop triggered button click). below code simplified include feel "problem" bits.
var value = sessionstorage.getitem(key); console.log(key + ' = ' + value); //produces correct key/value pair $('input[name="' + key +'"]').prop('checked') === value;
the checkboxes revert whatever current value is.
here's i've tried:
$('input[name="' + key +'"]').prop('checked', value); $('input[name="' + key +'"]').prop(':checked', value); $('input[name="' + key +'"]').attr('checked', value);
and pretty every other combination can possibly think of. appreciated.
note:
i can sub out variable simple true/false static value , functions correctly. if below, set checkboxes false or true depending on enter:
$('input[name="' + key +'"]').prop('checked', false);
for boolean
attributes checked
, have use boolean values. since using string, value going true.
$(element).prop ("checked", false) //false $(element).prop ("checked","false") //true
Comments
Post a Comment