Ajax JS problem (should be easy

Discussion in 'Programming' started by saturn100, Jun 2, 2011.

  1. #1
    I am trying to create a dynamic drop down list

    I was using the example shown on this site

    But am having no luck

    my code home page code is

    <html>
    	 
    	<head>
    	<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>
    Code (markup):
    anyone know whats wrong

    thanks
     
    saturn100, Jun 2, 2011 IP
  2. dotVince

    dotVince Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try posting a link to a live example. It can be debugged easier than sending just the code. Especially for JS issues.

    Thanks
     
    dotVince, Jun 3, 2011 IP