I have a multiple select tag, and I need to write the function onclick of it's options, because I need to get the value of last clicked option, but when I wrote the following
$("#multiple_select option").click(function()
{
var val = $(this).val();
alert(val);
});
it doesn't work in IE.
What is the problem?
I need exactly click event, because I wrote a function onclick event already(demo here), and I need to fix last changed element's value, which is impossible to make without click event(I think)
don't bind it on option
$("#multiple_select").click(function(){
alert("works");
});
accepted answer:
$(document).ready(function()
{
var options = $("#supply_cities_select :selected");
var lastOption;
$("#supply_cities_select").click(function()
{
lastOption = $(this).find(':selected').not(options);
options = $(this).find(':selected');
})
});
If you really want to have a click event
on each option, you need to have List
instead of a dropdown
style.
To accomplish that, add the size
attribute into the select
element for instance:
<select type="multiple" size=4>
<option>foo</option>
<option>bar</option>
<option>baseball</option>
</select>
Now you can bind each option
individually.
If you want to get the value of a clicked option use the change
event handler and .val()
method, like:
$("#multiple_select").change(function() {
var val = $(this).val();
alert(val);
});
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