5

Simple IE8 alert not working?

Why doesn't the following code snippet work in IE8?

<select>
    <option onclick="javascript: alert('test');">5</option>

      

Oddly enough, no warning is displayed in IE8. I also don't see the error icon in the left corner. Of course it works in FF and Opera. Any ideas?

+1


a source to share


3 answers


Putting a handler onclick

on an element <option>

seems ... strange to me. You might want to switch this to a more common event onchange

for <select>

. You can still do whatever you want, and this is the "accepted" way of doing what you want to do to choose. When doing this, you can try to remove the part javascript:

. This is only needed if you are executing Javascript in a link href

eg. The handler onclick

expects javascript.



+17


a source


Have you tried simply:

onclick="alert('test');"

      



Pretty sure you don't need the javascript prefix:

+4


a source


All versions of IE (6,7,8) do not support ANY event handlers on option elements.

This is a (rather) well known bug that the IE team pointed out that they are in no rush to fix. :-(

Then again Opera, Safari and Chrome have limited or no support for event handlers in parameters.

Lack of events in parameters: error 280

(related) Missing styles in preferences: error 281

It should be noted that "Edge" (think IE12 on Windows 10) currently shows that this issue has been fixed in preview versions.

+4


a source







All Articles