Load new dropdown box

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

    #1

    Load new dropdown box

    Hi all,

    I'm looking for a script that will initially display a first setof options
    on a dropdown box, after selecting the initial, it should load another
    dropdown box with a new set of values. Like selecting a category, then sub
    category - and those values needs to be posted with a standard html form.

    Can anyone send me some links to existing ones perhaps ?


    Thanx..
    RC


  • McKirahan

    #2
    Re: Load new dropdown box

    "RootChaos" <noreply@google .com> wrote in message
    news:ckljkt$t7v $1@ctb-nnrp2.saix.net. ..[color=blue]
    > Hi all,
    >
    > I'm looking for a script that will initially display a first setof options
    > on a dropdown box, after selecting the initial, it should load another
    > dropdown box with a new set of values. Like selecting a category, then sub
    > category - and those values needs to be posted with a standard html form.
    >
    > Can anyone send me some links to existing ones perhaps ?
    >
    >
    > Thanx..
    > RC[/color]


    Will this link help:




    Comment

    • McKirahan

      #3
      Re: Load new dropdown box

      "RootChaos" <noreply@google .com> wrote in message
      news:ckljkt$t7v $1@ctb-nnrp2.saix.net. ..[color=blue]
      > Hi all,
      >
      > I'm looking for a script that will initially display a first setof options
      > on a dropdown box, after selecting the initial, it should load another
      > dropdown box with a new set of values. Like selecting a category, then sub
      > category - and those values needs to be posted with a standard html form.
      >
      > Can anyone send me some links to existing ones perhaps ?
      >
      >
      > Thanx..
      > RC[/color]

      Here's an example; watch for word-wrap.

      <html>
      <head>
      <title>selects. htm</title>
      <script type="text/javascript">
      var data = new Array();
      data[0] = ":";
      data[1] = "Illinois:Chica go;Springfield" ;
      data[2] = "California :San Francisco;Los Angeles";
      data[3] = "New York:New York City;Rochester" ;
      function sels(what) {
      var form = document.forms[0];
      if (what == 0) {
      for (var i=0; i<data.length; i++) {
      item = data[i].split(":");
      form.sel1.optio ns[i] = new Option(item[0],i);
      }
      } else {
      form.sel2.optio ns.length = 0;
      var pick = form.sel1.optio ns[form.sel1.selec tedIndex].value;
      var item = data[pick].split(":");
      var city = item[1].split(";");
      for (var i=0; i<city.length; i++) {
      form.sel2.optio ns[i] = new Option(city[i],i);
      }
      }
      }
      </script>
      </head>
      <body onload="sels(0) ">
      <form>
      <b>State: </b>
      <select name="sel1" style="width:12 0" onchange="sels( 1)">
      </select>
      &nbsp; &nbsp;
      <b>City: </b>
      <select name="sel2" style="width:12 0">
      </select>
      </form>
      </body>
      </html>


      Comment

      • Matt Kruse

        #4
        Re: Load new dropdown box

        RootChaos wrote:[color=blue]
        > Can anyone send me some links to existing ones perhaps ?[/color]

        There are many out there.
        Here's mine, which has some features that most solutions lack:



        --
        Matt Kruse



        Comment

        • Seth Flowers

          #5
          Re: Load new dropdown box

          "RootChaos" <noreply@google .com> wrote in message news:<ckljkt$t7 v$1@ctb-nnrp2.saix.net> ...[color=blue]
          > Hi all,
          >
          > I'm looking for a script that will initially display a first setof options
          > on a dropdown box, after selecting the initial, it should load another
          > dropdown box with a new set of values. Like selecting a category, then sub
          > category - and those values needs to be posted with a standard html form.
          >
          > Can anyone send me some links to existing ones perhaps ?
          >
          >
          > Thanx..
          > RC[/color]

          Your best bet is using server side code to accomplish this, but I
          won't get into the pitfalls of javascript discussion. Here is a little
          bit of code that accomplishes this task... it should be self
          explanatory, arrayTxt is an array of the Text that is shown in the
          dynamic select box, and arrayVal is its corresponding array of values.
          If you want a little tutorial on this stuff, along with some browser
          compatibilities , look at http://www.quirksmode.org/js/options.html

          I tested this script on Windows IE 6, and Netscape 7.1, if you click
          the "Go" submit button, you should notice the querystring appended to
          the URL

          <html>
          <head>
          <script type="text/javascript">
          function AChange()
          {
          var aSelect = document.getEle mentById("aSele ct");
          if(aSelect.valu e=="seth")
          {
          var arrayTxt = new
          Array("sethText .txt","sethWeb. htm","sethDoc.d oc");
          var arrayVal = new Array("sethText ","sethWeb","se thDoc");
          AddBOptions(arr ayTxt,arrayVal) ;
          }
          else if(aSelect.valu e=="dan")
          {
          var arrayTxt = new
          Array("danText. txt","danWeb.ht m","danDoc.doc" );
          var arrayVal = new Array("danText" ,"danWeb","danD oc");
          AddBOptions(arr ayTxt,arrayVal) ;
          }
          else if(aSelect.valu e=="josh")
          {
          var arrayTxt = new
          Array("joshText .txt","joshWeb. htm","joshDoc.d oc");
          var arrayVal = new Array("joshText ","joshWeb","jo shDoc");
          AddBOptions(arr ayTxt,arrayVal) ;
          }
          }

          function AddBOptions(arr ayTxt,arrayVal)
          {
          var bSelect = document.getEle mentById("bSele ct");
          bSelect.options .length=0;
          if(arrayTxt.len gth==arrayVal.l ength)
          {
          for(var i=0;i<arrayTxt. length;i++)
          {
          bSelect.options[i]=new Option(arrayTxt[i],arrayVal[i]);
          }
          }
          }
          </script>
          <body>
          <form method="get">
          User
          <select id="aSelect" name="aSelect" onchange="javas cript:AChange() ;">
          <option value="DEFAULT" >Select First</option>
          <option value="seth">Se th</option>
          <option value="dan">Dan </option>
          <option value="josh">Jo sh</option>
          </select>
          <br /><br />
          Files
          <select id="bSelect" name="bSelect">
          <option value="DEFAULT" >Select Second</option>
          </select>
          <input type="submit" value="GO" />
          </form>
          </body>
          </html>


          seth flowers -- http://www.charlottewebdev.com

          Comment

          Working...