I'm trying to set this the way if "marketingAAA" is checked as true, a hidden checkbox "marketingPhone" is set as TRUE as well. This works.
However, if any other checkbox on the page is set to be TRUE, then it still goes TRUE for "marketingPhone". Can't figure this out why. It should stay as FALSE if "marketingAAA" is not checked TRUE. Does anyone see the issue?
$(function() {
var marketingAAA= $("input[type='checkbox']");
var marketingPhone = $("input[type='hidden'][name='marketingPhone']");
marketingAAA.on('change', function()
{
if ($(this).val() == "TRUE") {
marketingPhone.prop('checked',true);
marketingPhone.val('TRUE');
} else {
marketingPhone.prop('checked',false);
marketingPhone.val('FALSE');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="marketingrules" name="marketingBBB" type="checkbox" class="radio-button-input" value="TRUE">
<input id="marketing" name="marketingAAA" type="checkbox" class="radio-button-input" value="TRUE">
<input type="hidden" name="marketingPhone" value=""/>
var marketingAAA= $("input[type='checkbox']");is the issue here. You now select all checkboxes.$("#marketing")and$("#marketingrules")?marketingPhonedirectly depends onmarketingAAA, you can make use ofmarketingAAAvalue itself.