I have a form with several dropdown boxes.
If user choose "Other" from the dropdown menu, another div with an input field will slide down.
The problem is that I have 20+ dropdown boxes like that. Can I create only 1 function to trigger the related one?
Here is my html :
<div class="container">
<div>
<select id="option1" name="city">
<option value="">Please Choose</option>
<option value="Other">Other</option>
<option value="London">London</option>
</select>
</div>
<div id="box1">
<input type="text" name="city-other">
</div>
</div>
<div class="container">
<div>
<select id="option2" name="color">
<option value="">Please Choose</option>
<option value="Other">Other</option>
<option value="Red">Red</option>
</select>
</div>
<div id="box2">
<input type="text" name="color-other">
</div>
</div>
And my jQuery code :
$("#box1").hide();
$('#option1').on('change', function() {
if ( this.value == 'Other')
{
$("#box1").slideDown("slow");
} else {
$("#box1").slideUp("slow");
}
});
$("#box2").hide();
$('#option2').on('change', function() {
if ( this.value == 'Other')
{
$("#box2").slideDown("slow");
} else {
$("#box2").slideUp("slow");
}
});