IE capture option element onclick Aug08 '06

Feedback

# (1 of 16): Tom

1 week, 3 days after the fact. (Fri 18 Aug 2006, 9:09 AM CST)

Doesnt work if you want to select the first item on the dropdown

# (2 of 16): Matthom

1 week, 3 days after the fact. (Fri 18 Aug 2006, 9:13 AM CST)

Good point. Just put an empty <option> element as the very first list item. That way, the REAL first option still has to be selected, therefore using the onchange event.

Previous comment Return to entry

# (3 of 16): Tai

1 month, 1 week after the fact. (Tue 19 Sep 2006, 3:26 PM CST)

This dog bit me for like an hour. Hate IE...

Previous comment Return to entry

# (4 of 16): Stoyan » svest.org

5 months, 2 weeks after the fact. (Fri 19 Jan 2007, 10:36 AM CST)

Two remarks:

  1. onchange="do( document.getElementById("do").value )" is invalid, bacause it has double quotes enclosed in double quotes. The right way is ="do( document.getElementById('do').value )"
  2. There is no need of getElementById at all, just use 'this': <select onchange="do( this.value )">

Previous comment Return to entry

# (5 of 16): Stoyan » svest.org

5 months, 2 weeks after the fact. (Fri 19 Jan 2007, 10:39 AM CST)

And validate your feedback against html entities :) So the second remark should be: 2. There is no need of getElementById at all, just use 'this':

Previous comment Return to entry

# (6 of 16): Matthom

5 months, 2 weeks after the fact. (Fri 19 Jan 2007, 10:49 AM CST)

Got it Stoyan, thanks. I made those changes.

Previous comment Return to entry

# (7 of 16): Mary

12 months after the fact. (Fri 03 Aug 2007, 2:04 PM CST)

it doesn't work. i can't make that example working

Previous comment Return to entry

# (8 of 16): Phpster

1 year after the fact. (Mon 27 Aug 2007, 7:02 PM CST)

Thank you very much for this information... And I hate IE!! I don't know how can Microsoft Create and support such a lousy browser!

Previous comment Return to entry

# (9 of 16): Klaus T

1 year, 1 month after the fact. (Tue 18 Sep 2007, 10:49 AM CST)

Any way to include some kind of "else" in this script? So that if none of the "case" are true, it will run a different function?

Previous comment Return to entry

# (10 of 16): Dbu

1 year, 9 months after the fact. (Wed 07 May 2008, 9:35 AM CST)

Klaus, there is the "default:" part of the switch/case statement.

... case "Do That" : // SPECIFIC CODE HERE break; default: // fallback code break; ....

default is used if none of the cases matched.

Previous comment Return to entry

# (11 of 16): Zebulon Evans » zebulonevans.blogspot.com

1 year, 9 months after the fact. (Tue 20 May 2008, 7:24 PM CST)

If you are looking for just the onclick and you are not using the drop down in a form this should work for you:

Previous comment Return to entry

# (12 of 16): Zebulon Evans » zebulonevans.blogspot.com

1 year, 9 months after the fact. (Tue 20 May 2008, 7:27 PM CST)

This time with the markdown syntax. If you are looking for just the onclick and you are not using the drop down in a form this should work for you:



Previous comment Return to entry

# (13 of 16): Iflow » iflow.anju-web.com

1 year, 11 months after the fact. (Sat 05 Jul 2008, 2:27 AM CST)

Thank you very much for the article! I hate IE ! :)

Previous comment Return to entry

# (14 of 16): Dreas » itoar.info

2 years after the fact. (Wed 20 Aug 2008, 2:50 AM CST)

The reason that the example code doesnt work is because 'do' is a reserved word in javascript, used in the 'do...while' loop.

If you change the function name, it will work like a charm...

Previous comment Return to entry

# (15 of 16): Shane » hackosis.com

2 years, 2 months after the fact. (Fri 31 Oct 2008, 7:55 AM CST)

I am a javascript newbie (but a PHP apprentice), so please bare with me and thanks for the article, it is just what I was looking for.

What exactly does "optionValue" represent here? Is the the value that is being select from the dropdown box?

I have a good feeling I can do everything with this I need to with a PHP loop.

Previous comment Return to entry

# (16 of 16): Matthom

2 years, 2 months after the fact. (Fri 31 Oct 2008, 8:33 AM CST)

Shane, yes, optionValue represents the value being selected in the drop-down list.

Previous comment Return to entry

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

IE 6 does not support onclick event captures for <option> elements. Thankfully, there is still hope.

You are at the feedback permalink page for: IE capture option element onclick

Read more...