Dynamic select lists using optgroups again - without frameworks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pascal Ehlert

    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:


    I hope you can help me out this time!


    Many thanks in advance

    Pascal

  • Pascal Ehlert

    #2
    Re: Dynamic select lists using optgroups again - without frameworks

    Okay, sorry, I assume that was a stupid beginner's mistake.
    IE apparently doesn't support addEventListene r but has attachEvent.

    I fixed the problem that the stuff didn't get loaded like this:
    if (window.addEven tListener) {
    window.addEvent Listener('load' , initDynamicSele cts, false);
    } else {
    window.attachEv ent('onload', initDynamicSele cts);
    }

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



    Regards

    Pascal

    Comment

    • Pascal Ehlert

      #3
      Re: Dynamic select lists using optgroups again - without frameworks

      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

      Comment

      • The Natural Philosopher

        #4
        Re: Dynamic select lists using optgroups again - without frameworks

        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
        >

        Comment

        Working...