473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic select lists using optgroups again - without frameworks

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: http://pastie.caboo.se/140953 (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:
http://pascal.hacksrus.net/dev/sandbox.html

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

Pascal

Jan 19 '08 #1
3 1696
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.

Regards

Pascal

Jan 19 '08 #2
Okay, I do have one more question.
How can I determine whether to use e.target or e.srcElement (IE)?

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

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

Pascal

Jan 19 '08 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
3
by: Stewart | last post by:
Dear comp.lang.javascript, I have more than once wanted to manipulate the contents of select boxes dynamically, whilst the boxes contain <optgroup> tags. Manipulation of a select box containing...
2
by: taras.di | last post by:
Hi everyone, I've been reading up on how to create a drop down box who's context is dynamically produced based on the value of a previous select box. I've read a lot about some of the browsers...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
16
by: Brian D | last post by:
I have a multiple select list that is created dynamically based on a previous selection on an asp page. The first thing I do is to clear the curent option list by ...
1
by: madflytom | last post by:
Hello, I'm trying to move the options of one select list to another select list. The "source" select list is divided into optgroups, and the "target" select list is not. I want to somehow keep...
6
by: Pascal Ehlert | last post by:
Hi group! I was trying to build a JS solution for related select lists (child lists gets populated depending on the value selected in parent list), which uses no Ajax and is still "usable" in an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.