SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 dynamic drop downs

    Hey All,

    I have searched the forums and found an article with some code that I snatched, however! its not EXACTLY what I want, so I sent ahead and added an alert to display my problem:

    Code:
      <html> 
      <head> 
      <script language="javascript"> 
      function setOptions(o) 
      { 
      var select2 = document.form1.select2; 
      select2.options.length = 0; 
      if (o == "1") 
      { 
      select2.options[select2.options.length] = new Option('Apple'); 
      select2.options[select2.options.length] = new Option('Pear'); 
      } 
      if (o == "2") 
      { 
      select2.options[select2.options.length] = new Option('Carrot'); 
      select2.options[select2.options.length] = new Option('Potatoe'); 
      select2.options[select2.options.length] = new Option('Beans'); 
      select2.options[select2.options.length] = new Option('Corn'); 
      } 
      if (o == "3") 
      { 
      select2.options[select2.options.length] = new Option('Chicken'); 
      select2.options[select2.options.length] = new Option('Fish'); 
      } 
      } 
      </script> 
      </head> 
      <body> 
      <form name="form1"> 
     <select name="select1" size="1" onchange="setOptions(document.form1.select1.options[document.form1.select1.selectedIndex].value);"> 
      <option value="1">Fruit</option> 
      <option value="2">Vegetable</option> 
      <option value="3">Meat</option> 
      </select> 
      <br /> 
      <br /> 
      <select name="select2" size="1"> 
      <option>Apple</option> 
      <option>Pear</option> 
      </select>
      <br /><br />
     <input type="button" value="Get Value" onclick="alert ('First Drop: '+document.form1.select1.value +'\nSecond Drop:'+document.form1.select2.value)" />
      </form> 
      </body> 
      </html>
    If you click on the "Get Value" button with that code, you will see that the alert "Second Drop" has no value!

    What I am basically asking is if anyone knows how I would be able to a value assigned to the decond drop down menu? any idea's would be much appreciated!

    Thanks in advance
    /Ox
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     <html>
      <
    head>
      <
    script language="javascript">
      function 
    setOptions(o)
      {
      var 
    select2 document.form1.select2;
      
    select2.options.length 0;
      if (
    == "1")
      {
      
    select2.options[select2.options.length] = new Option('Apple','A1');
      
    select2.options[select2.options.length] = new Option('Pear','A2');
      }
      if (
    == "2")
      {
      
    select2.options[select2.options.length] = new Option('Carrot','B1');
      
    select2.options[select2.options.length] = new Option('Potatoe','B2');
      
    select2.options[select2.options.length] = new Option('Beans','B3');
      
    select2.options[select2.options.length] = new Option('Corn','B4');
      }
      if (
    == "3")
      {
      
    select2.options[select2.options.length] = new Option('Chicken','C1');
      
    select2.options[select2.options.length] = new Option('Fish','C2');
      }
      }
      
    </script>
      </head>
      <body>
      <form name="form1">
     <select name="select1" size="1" onchange="setOptions(document.form1.select1.options[document.form1.select1.selectedIndex].value);">
      <option value="1">Fruit</option>
      <option value="2">Vegetable</option>
      <option value="3">Meat</option>
      </select>
      <br />
      <br />
      <select name="select2" size="1">
      <option value="X1" >Apple</option>
      <option value="X2" >Pear</option>
      </select>
      <br /><br />
     <input type="button" value="Get Value" onclick="alert ('First Drop: '+document.form1.select1.value +'\nSecond Drop:'+document.form1.select2.value)" />
      </form>
      </body>
      </html> 

  3. #3
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That Simple

    WOW, that simple when you know how, thanks very much vwphillips, life saver
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net


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
  •