onclick on option tag not working on IE and chrome

html, html-select

Solution

`onclick` event on `option` tag will fail on most versions of IE, Safari and Chrome: reference

If you want to trigger an event whenever user select, why not simply use:

<select onclick="check()">
<option>one</option>
<option>two</option>
<option>three</option>

And if you want to do something with the specific option user selected:

<select onclick="if (typeof(this.selectedIndex) != 'undefined') check(this.selectedIndex)">
<option>one</option>
<option>two</option>
<option>three</option>

This way you are guaranteed to call `check()` if and only if an option is selected.

Edit: As @user422543 pointed out in the comments, this solution will not work in Firefox. I therefore asked another question here: Why does Firefox react differently from Webkit and IE to "click" event on "select" tag?

So far it seems using `<select>` tag is will not work consistently in all browsers. However, if we simulate a select menu using library such as jQuery UI select menu or Chosen to create a select menu instead of using `<select>` tag, `click` event will be fired on `<ul>` or `<li>` tag which is consistent in all browsers I tested.

Problem

I am using `onclick` event in option tag for `select` box ``` <select> <option onclick="check()">one</option> <option onclick="check()">two</option> <option onclick="check()">three</option> </select>` ``` `onclick` event is not working on IE and Chrome but it is working fine in firefox, here I don't want to use `onchange` event on select tag bcz it will not trigger an event if user selects same option again Eg:say first time user selects "one" dropdown I will open a popup after processing some stuff user closes the popup,suppose if user wants to select same "one" dropdown it will not trigger any event.this can be solved using onclick event on option tag but its not working on IE and chrome Is there any work around for this ?

Original source

Related problems