Goal is to update checkbox fields to equal TRUE or FALSE, depending which radio button option is picked. If I select FALSE, then the checkboxes must be unchecked.
I'm only able to get the checkboxes ticked if I select TRUE. Is it because I defined that as a value?
$(function() {
var MAIN= $("input[type='radio'][value='TRUE']");
var marketing1 = $("input[type='checkbox'][value='']");
var marketing2 = $("input[type='checkbox'][value='']");
MAIN.on('change', function()
{
if ($(this).val() == "TRUE") {
marketing1.prop('checked',this.checked);
marketing2.prop('checked',this.checked);
} if ($(this).val() == "FALSE") {
marketing1.prop('checked',this.checked, false);
marketing2.prop('checked',this.checked, false);
}
});
});
From HTML
<input type="radio" name="MAIN" value="TRUE"/> Yes
<input type="radio" name="MAIN" value="FALSE"/> No
First - <input type="checkbox" name="marketing1" value=""/>
Second - <input type="checkbox" name="marketing2" value=""/>
Aucun commentaire:
Enregistrer un commentaire