Onclick doesn't work in Chrome

11,619

Solution 1

<select class="input" onchange="window.location.href = this.value" style="width:200px">
        <option>---</option>
        <option value="link.php">one</option>
        <option value="link2.php">two</option>
    </select>

I know its not EXACTLY the same... but having a click event on the option of a select list is not good practice. Instead of onchange, you could have onclick as well... but onchange really is the way to do this, in my opinion.

Solution 2

Probably the safest approach is to use the onchange event of the select element, and use its value to determine the action to take. I don't think onclick works for option in IE, either.

Solution 3

Are the double quotes inside the onclick attributes not meant to be single quotes ?

Share:
11,619
good_evening
Author by

good_evening

Updated on September 23, 2022

Comments

  • good_evening
    good_evening over 1 year
        <select class="input" style="width:200px">
            <option>---</option>
            <option onclick="window.location="link.php">one</option>
            <option onclick="window.location="link2.php"">two</option>
        </select>
    

    It doesn't work in chrome, it work in opera/mozilla and so on. Any advice?