views:

43

answers:

4
<select>
            <option value="0" id="n">n</option>
            <option value="1" id="m">m</option>
</select>

In JQuery, how do I say:

When id "n" is selected...do this . (not onclick) I want onSelected.

A: 

See this link

Dee
A: 

You could use the change eventhandler

http://api.jquery.com/change/

josnidhin
A: 

Instead of writing onclick for each option tag, I recomment use onchange event of select. Another advantage of writing this will be you don't need to care event bubbling or event capturing and you have one method declared on select tag.

Adeel
A: 

No need to use id's for options inside a select tag.

$(function(){
    $("#sel1").change(function(){
        switch($(this).val())
        {
            case "0": // do your code
                      break;
        }
    });
});
<select id="sel1">
            <option value="0" id="n">n</option>
            <option value="1" id="m">m</option>
</select>
rahul