I have a form for a client that needs to have checkboxes checked when a selection is made from a drop down. I have the following code:
$(document).ready(function() { $("#Field8").change(function() { var text = $('#Field8 :selected').text(); $('#Field21-0, #Field34-0, #Field35-0').prop('checked', text === 'Injury'); $('#Field18-0').prop('checked', text === 'Near Miss'); $('#Field19-0').prop('checked', text === 'Moving Violation'); $('#Field22-0, #Field35-0').prop('checked', text === 'Subcontractor'); $('#Field23-0, #Field35-0').prop('checked', text === 'Property'); }); });
This does the job for each individual drop down selection, but if the field is repeated in another line it won't show up. For example, when I select 'Injury' from the drop down, 'Field35-0' does not get checked, but does get checked when I select 'Property' even though it belongs to both and should be checked. I'm not sure why the code is behaving like this.
I've tried separating out the code and repeating the whole process but it ends up with the same result as I described. I'm a newbie at scripting and I'm sure there is some line here that I am missing.