I am displaying/hiding form elements based on a user dropdown select option, the following script is meant to add/remove required attributes on the fields, however, it seems that validation is not taking this into account, could it be that validation script only runs on page load rather than on dynamic form changes? if so, how can I make it listen to changes in form required fields.
Remove the validation log from OnChange function and add the logic in the form Validation function. The form validation function will look like this
alert("Company Name is required"); // you may want show it in error div via innerHTML
and the submit button will have this onclick attribute.