views:

29

answers:

1

I want to display a different form for different selections of this drop down list:

<label>
    <select name="type" id="type">
<option value="object" selected="selected">Object</option>
<option value="number">Number</option>
<option value="text">Text</option>
<option value="date">Date</option>
<option value="time">Time</option>
<option value="geo">Geospatial</option>
<option value="currency">Currency</option>
</select>
</label>

What would be the jQuery event that is triggered when a user selects one of these options. Would the .click() event be triggered in this case as well?

+7  A: 

You should use the change event. Click will be triggered on every mouse click, which is not what you want, and it'll be triggered even if the user clicks on the combo but doesn't change the value.

Also, click won't be good for keyboard navigation, so change is the way to go:

$("#type").change(function (){
  // Do whatever you want
});
Seb
Thanks $("#type").change(function (){ var selectText = $('#type :selected').text(); alert(selectText); })Alerts the value
Ankur
Ankur - You should this as the answer
Pablo
@Pablo - if you mean select this as the answer, yes, I agree. Unfortunately you can't select an answer immediately even if you know that it is correct.
Ankur