I have a form that needs to display specific select options ("locations") based on the user's ZIP, which is in a number field above. In this example, I need the option "Out of Range" to hide and the "In Range" to show when the user enters "12345" in the input.
This is my HTML:
<!--Zip-->
<div class="zip-field">
<label for="zip">Zip Code</label>
<input type="number" id="zip" name="zip" />
</div>
<!--Location-->
<div class="location-field">
<label for="location">Location</label>
<select id="location" name="location">
<option value="In Range">In Range</option>
<option value="Out of Range">Out of Range</option>
</select>
</div>
This is my jQuery:
$('#zip').on('change',function(){
if ( $(this).val() == "12345" ) {
$("#location option[value='In Range']").show();
$("#location option[value='Out of Range']").hide();
}
});
Should be pretty straightforward, but no cigar.