By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Dynamic select lists using optgroups again - without frameworks

P: n/a
Hi group!

After my first post a few days ago and your advice not to use the
Prototype Framework (which indeed was a good idea! ;-)) I rewrote my
script for dynamic select lists.
This is what it looks like now: (I know
it's messy, but I don't see another way)

Let me explain how it works in short.
First it get's all select elements with classes dynamic_select and
parent in one array and the related child elements with classes
dynamic_select and child in another.

Then I loop through them and extract the options into
grouped_options_store and store the index as the rel attribute of the
parent element.

When the value now changes it determines the text of the selected
parent item and looks for an optgroup with that text as a label.
If it can find one it inserts thoses options from grouped_options_store
into the second list.

Unfortunately I'm having the exact same problem as with the old
version, it works fine in Firefox and Safari but when I select a parent
item in the first list the second list just doesn't change.
It displays the unformatted optgroups from the markup.

Here is a live example again:

I hope you can help me out this time!
Many thanks in advance


Jan 19 '08 #1
Share this Question
Share on Google+
3 Replies

P: n/a
Okay, sorry, I assume that was a stupid beginner's mistake.
IE apparently doesn't support addEventListener but has attachEvent.

I fixed the problem that the stuff didn't get loaded like this:
if (window.addEventListener) {
window.addEventListener('load', initDynamicSelects, false);
} else {
window.attachEvent('onload', initDynamicSelects);

There are some other problems still, but I hope I can sort them out on my own.



Jan 19 '08 #2

P: n/a
Okay, I do have one more question.
How can I determine whether to use or e.srcElement (IE)?

This throws an error in IE (target is 'null' or not an object):

if ( {
target =
} else {
target = e.srcElement;


Jan 19 '08 #3

P: n/a
Pascal Ehlert wrote:
>understood that JS shouldn't be treated as a way to quickly add
some eyecandy to your page but wants to be understood.
I promise to give my best to understand it! :-)

I understand also that pencils should not be used to clean your ears of
wax, but when wax and pencils is all you have, it works well enough ;-)

-- Pascal Ehlert
Jan 20 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.