What's the event to bind for when a select form is selected?
I have something like this:
<select id='list'> <option value='1'>Option A</option> <option value='2'>Option B</option> <option value='3'>Option C</option> </select>
When Option B is selected, I want some function to run.
So what do I bind,
$("#list").bind("?", function (){ // How do I check if it's option b that's selected here //blah blah });
The HTML Select DropDownList has been assigned a jQuery OnChange event handler. When an item is selected in the HTML Select DropDownList, the jQuery OnChange event handler is executed within which the Text and Value of the selected item is fetched and displayed in JavaScript alert message box.
$('#mySelectBox option'). each(function() { if ($(this). isChecked()) alert('this option is selected'); else alert('this is not'); });
jQuery select() MethodThe select event occurs when a text is selected (marked) in a text area or a text field. The select() method triggers the select event, or attaches a function to run when a select event occurs.
select() method selects all the text in a <textarea> element or in an <input> element that includes a text field.
This jQuery snippet will get you started:
$('#list').change(function() { if ($(this).val() === '2') { // Do something for option "b" } });
the event you are looking for is change
. more info about that event is available in the jquery docs here: http://docs.jquery.com/Events/change#fn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With