Set field as required on portal form based on option from dropdown

0
34
Forum Post: Change the Filter On option on Opportunity Associated View for Account form


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');
    }
}



Source link

Leave a reply

Please enter your comment!
Please enter your name here