I'm trying to get the script to hide/show fields, depending on the picklist selection. Though, I cannot get the script to run.
Any input is greatly appreciated.
This is the script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> <script/>
<script>
$("#seeAnotherField").change(function() {
if ($(this).val() == "yes") {
$('#otherFieldDiv').show();
$('#otherField').attr('required', '');
$('#otherField').attr('data-error', 'This field is required.');
} else {
$('#otherFieldDiv').hide();
$('#otherField').removeAttr('required');
$('#otherField').removeAttr('data-error');
}
});
$("#seeAnotherField").trigger("change");
</script>
<div class="form-group">
<label for="seeAnotherField">Do You Want To See Another Field?</label>
<select class="form-control" id="seeAnotherField">
<option value="no">No Way.</option>
<option value="yes">Absolutely!</option>
</select>
</div>
<div class="form-group" id="otherFieldDiv">
<label for="otherField">Here you go!</label>
<select class="form-control" id="otherField">
<option>Yay</option>
<option>Woo</option>
<option>Hazah</option>
<option>Yipee</option>
<option>Hoorah</option>
</select>
</div>