Take a look at my fiddle:
This is the snippet of my html code:
<legend>Team Type</legend>
<label>* Select Type :</label>
<select name="team_type" style="width:150px;" id="team_type">
<option value="1">Baseball</option>
<option value="2">Soccer</option>
</select>
<div style="clear: both"></div>
// Many more league options...
</select>
This portion shows my javascript code:
$("#team_type").bind("change",function() {
$(".league_group").hide();
$(".league_group_"+$(this).val()).show();
$("#league_type").val($(".league_group_"+$(this).val()+":first-child").val());
});
And this is what I'm aiming for:
I aim to automatically select the first visible option in the league group corresponding to the selected team type whenever a user makes a selection.
For instance, if soccer is chosen in team_type
, then the league_type
should automatically choose the first child of league_group_1
and vice versa.