Cascading select boxes.

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

    Cascading select boxes.

    We have had this script on our site for a while, and it has always
    worked in any browser we have tested. It dynamically fills one select
    based on the selection of another select. Unfortunatly, with the
    release of NS 7, and the related Mozilla engine, this script no longer
    works.

    function popPresList(lst Parent,lstChild ){
    clearPresList(l stChild);
    var n = lstParent.optio ns[lstParent.selec tedIndex].value; // get the
    index of the controlling select.
    var k = 0;
    lstChild.option s[++k] = new Option('Not Selected', '0'); // add the
    default selection to the child list.
    if ( n > 0 )
    {
    for(i=0;i<aPres Holder.length;i ++) // look through the array to
    find the proper child array.
    {
    var presArray = aPresHolder[i];
    if(presArray['parent']==n) // does its parent match ours?
    {
    txtItem = presArray['name']; // get the text
    optValue = presArray['id']; /get the value
    lstChild.option s[++k]=new Option(txtItem, optValue); //
    create a new option
    }
    }
    }
    if(k == 0)
    {
    lstChild.option s[++k] = new Option('None Available', '0'); //if
    we have no children, display to user.
    }
    lstChild.select edIndex=1; // set the seletected index.
    }

    function clearPresList(l stChild)
    {
    var longi = lstChild.length ;
    for ( var i=0; i<=longi -1; i++ )
    {
    lstChild.option s[i] = null; // clear the present options
    }
    }

    The html (stripped of surrounding tables, etc,)


    <select name='PRESENTAT ION_SELECT'
    onChange='javas cript:popPresLi st(this,PRESENT ATION_SELECT_CH ILD);'>
    <option value='0'>Not Selected</option>
    <option value=301 >Poster</option>
    <option value=302 >Oral</option>
    </select>
    <select name='PRESENTAT ION_SELECT_CHIL D'>
    <option value='0'>Not Selected</option>
    <option value=1381 >Research</option>
    </select>

    can anyone shed some light on why this has stopped working, and what I
    must to to fix it?
  • Lasse Reichstein Nielsen

    #2
    Re: Cascading select boxes.

    greg.mowery@sch olarone.com (Greg) writes:
    [color=blue]
    > We have had this script on our site for a while, and it has always
    > worked in any browser we have tested. It dynamically fills one select
    > based on the selection of another select. Unfortunatly, with the
    > release of NS 7, and the related Mozilla engine, this script no longer
    > works.[/color]

    That would be little more than a year ago, if you take the Mozilla 1.0
    release as a guide. Ofcourse, Netscape 6 was based on a pre-1.0 version,
    and people have been using Mozilla for several years.
    [color=blue]
    > can anyone shed some light on why this has stopped working, and what I
    > must to to fix it?[/color]

    In a Mozilla based browser, if you enter "javascript :" in the address
    line or start the javascript console from the menu, what error message
    does it show?

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Cascading select boxes.

      greg.mowery@sch olarone.com (Greg) writes:
      [color=blue]
      > We have had this script on our site for a while, and it has always
      > worked in any browser we have tested. It dynamically fills one select
      > based on the selection of another select. Unfortunatly, with the
      > release of NS 7, and the related Mozilla engine, this script no longer
      > works.[/color]

      I am testing in Mozilla Firebird, one of the more recent versions.

      Comments:
      [color=blue]
      > for(i=0;i<aPres Holder.length;i ++) // look through the array to[/color]

      The "aPresHolde r" variable declaration isn't included here, so this
      part is hard to test.

      ....
      [color=blue]
      > optValue = presArray['id']; /get the value[/color]

      This comment needs another "/". I get an "unterminat ed regular
      expression literal" error.


      Is there a form around these select elements?
      [color=blue]
      > <select name='PRESENTAT ION_SELECT'
      > onChange='javas cript:popPresLi st(this,PRESENT ATION_SELECT_CH ILD);'>[/color]

      Here "PRESENTATION_S ELECT_CHILD" is not defined as a global variable.
      Try changing it to
      this.form.eleme nts["PRESENTATION_S ELECT_CHILD"]
      if there is a surrounding form. Otherwise try
      document.getEle mentsById("PRES ENTATION_SELECT _CHILD")
      and add the id attribute to the second select too.

      The "javascript :" is unnecessary.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...