2

I have the following dropdown

<select onchange="myFunc(argument here)" id="propertydropdown">
<option value="tags">blah</option>
<option value="tags2">blahblah</option>
<option value="tags3">blahblahblah</option>
</select>

how do i get the argument to be the value of the option currently selected?

LemonMan
  • 2,963
  • 8
  • 24
  • 34
  • @Bergi - ^^^ sounds like an answer! – adeneo Aug 08 '13 at 23:22
  • possible duplicate of [jQuery get value of select onChange](http://stackoverflow.com/questions/11179406/jquery-get-value-of-select-onchange) or [How to get the selected value of dropdownlist using JavaScript?](http://stackoverflow.com/questions/1085801/how-to-get-the-selected-value-of-dropdownlist-using-javascript) if you prefer a non-jQuery question (the answer is the same) – Bergi Aug 08 '13 at 23:24

2 Answers2

4

Simply myFunc(this.value), since this == document.getElementByID("propertydropdow") in the handler

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

I'm not sure how you could pass the selected value as an argument, but what you could do is within the handler itself use this to work out the value (this will be the select):

function myFunc() {

    var value = this.options[ this.selectedIndex ].value;

   // ...do stuff

}

You might even be able to do onclick="myFunc( this.options[ this.selectedIndex ].value );", but I haven't tried that.

SimonR
  • 1,248
  • 9
  • 10