SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OPTGROUP in forms - other options?

    Info from:

    http://www.w3.org/TR/html4/interact/forms.html

    I am trying to create a multiple selectable SELECT menu however I also want to have categories in this menu, so the menu might look like:

    Category 1
    >> Select Option
    >> Select Option
    >> Category 2
    >> >> Select Option
    >> >> Select Option
    Category 3
    >> Selection Option

    for example. Now this OPTGROUP would be perfect but it only works one level deep. Can anyone think of an alternative to this, perhaps using javascript which prevents the user from selecting the categories?

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be ugly but assuming you are hardcoding the values for the dropdown you could set up an onchange event for the dropdown that would evaluate the selectedIndex.

    However, I think your options are limited from there. You could either 'bump' them down to the first sublevel for the level they selected or you could throw an alert box or both.

    PSEUDOCODE, assuming you are calling this function from onchange event:

    function checkLevel(this) {
    if(this.selectedIndex == 0 || this.selectedIndex == 3) {
    this.selectedIndex = parseInt(this.selectedIndex) + 1;
    alert("You can select sublevels only");
    }

    }

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see where you are going with that. All the stuff is written by PHP so being dynamically generated anything can be done. I have written a php function at the moment just to add the assocaited -- tags to increase the length. What is nice about the html OPTGROUP idea is that you can't select the category title. Changing the font face/text of the category could be done by CSS so hopefully that will be enough to make it clear.

    I see what you mean about the Onchange idea, I probably will do something like that. Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •