1

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>
Parag
  • 369
  • 3
  • 8
  • 28

2 Answers2

1

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.

Jumpa
  • 878
  • 1
  • 8
  • 12
0

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
    ....
});
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105