problem with javascrpt drop down menu need help

Discussion in 'JavaScript' started by saturn100, Jul 3, 2011.

  1. #1
    Hi
    I am trying to create a dynamic drop down list based on JS
    I am using this sample here

    but its not working.Anyone know what I am doing wrong here is my script

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript">
    function setOptions(chosen) {
    var selbox = document.myform.opttwo;
     
    selbox.options.length = 0;
    if (chosen == " ") {
      selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
     
    }
    if (chosen == "1") {
      selbox.options[selbox.options.length] = new
    Option('first choice - option one','oneone');
      selbox.options[selbox.options.length] = new
    Option('first choice - option two','onetwo');
    }
    if (chosen == "2") {
      selbox.options[selbox.options.length] = new
    Option('second choice - option one','twoone');
      selbox.options[selbox.options.length] = new
    Option('second choice - option two','twotwo');
    }
    if (chosen == "3") {
      selbox.options[selbox.options.length] = new
    Option('third choice - option one','threeone');
      selbox.options[selbox.options.length] = new
    Option('third choice - option two','threetwo');
    }
    }
    </script>
    </head>
    
    <body>
    
    
    <form name="myform"><div align="center">
    <select name="optone" size="1"
    onchange="setOptions(document.myform.optone.options
    continued from previous line[document.myform.optone.selectedIndex].value);">
    <option value=" " selected="selected"> </option>
    <option value="1">First Choice</option>
    <option value="2">Second Choice</option>
    <option value="3">Third Choice</option>
    </select><br> <br>
    <select name="opttwo" size="1">
    <option value=" " selected="selected">Please select one of the options above first</option>
    </select>
    <input type="button" name="go" value="Value Selected"
    onclick="alert(document.myform.opttwo.options
    continued from previous line[document.myform.opttwo.selectedIndex].value);">
    </div></form>
    </body>
    </html>
    
    HTML:
    thanks
     
    saturn100, Jul 3, 2011 IP
  2. tolas

    tolas Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've got a nice free menu component for you at http://mediabeez.ws
    It works, is free, and is indexable by search-engines.
     
    tolas, Jul 9, 2011 IP