I am using the below code to show/hide a field based on a selection in a dropdown box. The show/hide feature is working correctly but I want to make the field that is shown mandatory but .attr('required', true); does not appear to be working.
How can I achieve making input into this field mandatory?
// Make vet reg required if the occupation is PVP $(document).ready(function() { $("#ahi_occupation").change(SetVetRegRequired); $("#ahi_occupation").change(); }); function SetVetRegRequired() { var selectedValue = $("#ahi_occupation").val(); if (selectedValue == "100000002") { $("#ahi_vetreg_label").closest("tr").show(); $("#ahi_vetreg").show().attr('required', true); } else { $("#ahi_vetreg_label").closest("tr").hide(); $("#ahi_vetreg").hide().removeAttr('required'); } }