Reputation: 379
I have a multiple select list. on select for an option from the list,I am calling a javascript function. I want to pass the current selected option object to this javascript function.
How can I do this? I tried following but its not working.
<select onClick="callJavascriptFun(this.option);" >
</select>
Upvotes: 1
Views: 1618
Reputation: 908
for getting the selected option, try the following code:
<select onchange="callJavascriptFun(this.options[this.selectedIndex]);" >
</select>
inside the callJavascriptFun function you will get of course the selected option.
Upvotes: 1
Reputation: 92854
Make it easier with event handler:
html part
<select class="list">
</select>
js part:
$('select.list').change(function(){
var selectedOption = $('option:selected', $(this)); // your selected option object(element)
var current = $(this).val(); // your selected option value
....
});
Upvotes: 0