Women in Technology

Hear us Roar



Article:
  Cooking with JavaScript & DHTML
Subject:   <optgroup> support?
Date:   2004-12-03 12:54:34
From:   euscten
Excellent script. I was wondering if there would be a way to modify it to do typeahead for <optgroup> tags instead of <option> tags. I have a long long list of option groups with 3 or 4 options per group and the typeahead functionality would be immensely useful. Any thoughts or input would be appreciated.
Full Threads Newest First

Showing messages 1 through 3 of 3.

  • <optgroup> support?
    2004-12-03 12:55:42  euscten [View]

    The Subject line was filtered - it should be optgroup support?
  • <optgroup&rt; support?
    2004-12-05 22:53:46  Danny Goodman | O'Reilly Author [View]

    It might be possible depending on how rigid your page needs to validate (X)HTML.


    Key lines to modify would be:


    var selectOptions = selectElem.options;

    and:


    txt = selectOptions[i].text.toUpperCase();

    The righthand side of the first statement would be changed to return all optgroup elements of the select tag (selectElem.getElementsByTagName("optgroup")). The righthand side of the second statement would be changed to read the id attribute of the optgroup (assuming you assign the keyed word(s) to each optgroup's id attribute).


    That leaves what you do with the typeahead. Since the optgroup elements themselves are not selectable, you'll have to decide if the desired user interface is to select the first nested option. If so, you'll need to have a correlation somewhere between a particular optgroup element and the index value of its first nested option within the select element (i.e., to set the select element's selectedIndex property). You could do a custom attribute of the optgroup elements (thus breaking traditional validation), or perhaps create a pseudo-hash table which the typeahead function uses for lookup whenever it finds a match of the optgroup's id.



    I don't know if this making any sense (I don't know your scripting skill level), and I haven't tried to implement my suggestions. But it's where I'd start to attack the problem.

    • <optgroup> support?
      2004-12-05 22:55:28  Danny Goodman | O'Reilly Author [View]

      Fixed the subject line. zzz