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?

2

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

6 Comments

yup that's the answer thanks!
how would I do this if I have <input onchange="tcUpdate(argument)" type="color" name="favcolor">
@Lemonio: It's the same actually?
i don't think my onchange is working then, though maybe i'm just doing something else wrong
nvm found a workaround
|
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.