Call function based on dropdown selection

13,923

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

Share:
13,923
LemonMan
Author by

LemonMan

Updated on June 04, 2022

Comments

  • LemonMan
    LemonMan almost 2 years

    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
    LemonMan over 10 years
    yup that's the answer thanks!
  • LemonMan
    LemonMan over 10 years
    how would I do this if I have <input onchange="tcUpdate(argument)" type="color" name="favcolor">
  • Bergi
    Bergi over 10 years
    @Lemonio: It's the same actually?
  • LemonMan
    LemonMan over 10 years
    i don't think my onchange is working then, though maybe i'm just doing something else wrong
  • LemonMan
    LemonMan over 10 years
    nvm found a workaround
  • P-RAD
    P-RAD over 9 years
    if the text contain spaces I can only access the first word