<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?
Your handler should be on your select element, not on the option elements. Try adding an onChange handler on your select element and reference the selected dropdown item on the events target. value property in your handler.
The onclick attribute is an event attribute that is supported by all browsers. It appears when the user clicks on a button element. If you want to make a button onclick, you need to add the onclick event attribute to the <button> element.
addEventListener can add multiple events to a particular element. onclick can add only a single event to an element.
This is a type of JavaScript link - the onclick attribute defines a JavaScript action when the 'onclick' event for the link is triggered (i.e. when a user clicks the link) - and there is a URL present itself in the onclick attribute.
<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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With