Hello,
I have a form that asks the user if they would like to be contacted as a follow up via a drop down menu. If they answer yes (which is default), this leaves the field required but should they not wish to be and they select "No", it removes the requirement from the fields.
The jQuery I created works at removing the requirement, however, when I try to switch back to "Yes", the field's requirement class is added back but can still be submitted without the fields having been entered.
Here's my code:
I'm not sure what's at play here, can anyone offer any suggestions?
I have a form that asks the user if they would like to be contacted as a follow up via a drop down menu. If they answer yes (which is default), this leaves the field required but should they not wish to be and they select "No", it removes the requirement from the fields.
The jQuery I created works at removing the requirement, however, when I try to switch back to "Yes", the field's requirement class is added back but can still be submitted without the fields having been entered.
Here's my code:
<script> jQuery('#contact_you').change(function(){ if(this.value == "Yes") { jQuery('#name').html('<input class="validate['required'] gvalidate_valid" id="your_name" name="your_name" type="text" value="">'); jQuery('#phone').html('<input class="validate['required'] gvalidate_valid" id="your_phone" name="your_phone" type="text" value="">'); jQuery('span.check_first').addClass("required").removeClass("hidden"); } else { jQuery('#name').html('<input class="" id="your_name" name="your_name" type="text" value="">'); jQuery('#phone').html('<input class="" id="your_phone" name="your_phone" type="text" value="">'); jQuery('span.check_first').removeClass("required").addClass("hidden"); } }); </script>
I'm not sure what's at play here, can anyone offer any suggestions?