optgroup onclick

Discussion in 'HTML & Website Design' started by Jamie18, Oct 2, 2007.

  1. #1
    this is part html and part javascript, so sorry if you think i should have posted in the other forum..

    i'm having a problem attempting to add an onclick event to an optgroup.

    the functionality i want is to click the optgroup and have some javascript to than populate what's inside the optgroup..

    i.e.

    <select id="someselect" name="someselect">
       <optgroup label="firstgroup" onclick="populate_firstgroup">..some options here.. </optgroup>
       <optgroup label="secondgroup" onclick="populate_secondgroup">...some options here...</optgroup>
       <optgroup label="thirdgroup" onclick="populate_thirdgroup">...some options here...</optgroup>
       <optgroup label="fourthgroup" onclick="populate_fourthgroup">...some options here...</optgroup>
       ... more optgroups
    </select>
    
    <script type="t/j">
      function hiding()
      {
         \\removes all options from list if java is enabled -- otherwise all options are given
         var selectlist = document.getElementById("someselect");
         for (var i = 0; i < selectlist.options.length; i)
         {
            selectlist.options[i] = null;
         }
         .... 
      }
    
      function populate_firstgroup()
      {
        hiding(); //remove all old options
    
        var opt_group = document.getElementById("firstgroup");
        var opto = document.createElement('option');
        opto.innerText=i; //for IE
        opto.text=i; //for firefox
        opto.value=i;
        opt_group.appendChild(opto);
    
        .... add more options
      }
    
      .... more similar populate functions
    
    bodyonload=hiding();
    </script>
    
    Code (markup):
    this works perfectly in firefox.. but of course.. IE6 doesn't want to let me do it.. it appears as though IE doesn't even want to pretend that optgroups are clickable..

    anyone have any ideas how i can get this to work? my first thought is just to add a div around the optgroups.. but that just doesn't seem like the cleanest route.. or if you have an entirely different idea for doing the same thing.. i thought of just using 2 selects one for optgroups and one for options.. but i've done that too many times and want to try something different.
     
    Jamie18, Oct 2, 2007 IP