I would like to make a field required if a checkbox is checked. I used the code in this thread: https://answers.laserfiche.com/questions/56221/dynamically-change-required-fields#67876
$(document).ready(function () {
$('.checkbox input').change(function () {
if ($(this).is(':checked')) {
$('.req span.cf-required').remove();
$('.req input').removeClass('required').removeAttr('required');
} else {
$('.req label').append('<span class="cf-required">*</span>');
$('.req input').attr('required', 'True');
}
})
});
But flipped it around with the intent to make it required if checked, instead of not required, here is a sample:
//This is for the Contact Resistance Test
$(document).ready(function () {
$('.ckboxConResis input').change(function () {
if ($(this).is(':checked')) {
$('.reqNAConResis label').append('<span class="cf-required">*</span>');
$('.reqNAConResis input').attr('required', 'True');
//alert('if');
} else {
$('.reqNAConResis span.cf-required').remove();
$('.reqNAConResis input').removeClass('required').removeAttr('required');
}
})
});
But it doesn't work, it puts the little red * next the field if the checkbox is checked, but I can still submit the form.
Thanks in advance,
Alon