I have a section of Yes, No, N/A questions (class= preop). I want the multi-line Comment field (class= comment) to become required if any on the questions are checked No. I have the following script I found on LF Answers and modified, but it works when one questions is marked No and then removes the required field whenever another question is marked Yes or N/A. In addition, it adds an asterisk every time No is selected which when more than one No is selected looks weird. Can anyone help me properly modify this script? I am new to JavaScript.
$(document).ready(function () {
$('.preop input').change(function () {
if ($(this).val() == 'No'){
$('.comment label').append('<span class="cf-required">*</span>');
$('.comment textarea').attr('required', 'True');
} else {
$('.comment span.cf-required').remove();
$('.comment textarea').removeClass('required').removeAttr('required');
}
})
});