www.webdeveloper.com
Results 1 to 2 of 2

Thread: Dynamic menu help please

  1. #1
    Join Date
    Nov 2007
    Posts
    19

    Question Dynamic menu help please

    Hello everybody!

    I need to build a select-box menu where the first selection determines the options in the next select-box and so forth. Something like this http://www.onlinegolf.co.uk/mens/gol...og/1428pog.asp where you first select what "hand" and then "loft".

    What type of application is this, PHP / Javascript ??? and what would the name for this kind of thing be (if I need to do a tutorial search)

    Best regards
    Anders Thiele

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    dynamic select menu
    This one's JavaScript. A server side solution would also be required.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>select change 2nd select</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <script type="text/javascript">
    var varieties=[
    ["varieties","granny smith","golden delicious","jonathan"],
    ["varieties","anjou","bartlett","conference"],
    ["varieties","valencia","pineapple","pera"]
    ];
    
    function Box2(idx) {
    var f=document.myform;
    f.box2.options.length=null;
    for(var i=0; i<varieties[idx].length; i++) {
    	f.box2.options[i]=new Option(varieties[idx][i], i); 
        }    
    }
    
    window.onload=function() {
    var box1=document.myform.box1;
    box1.onchange=function(){Box2(this.selectedIndex);};
    // create 2nd select
    try { // IE
      var sel=document.createElement("<select name=\"box2\"><\/select>");
      }
    catch(e) {
      var sel=document.createElement("select");
      sel.name = "box2";
      }
    document.myform.getElementsByTagName('fieldset')[0].insertBefore(sel, box1.nextSibling);
    // fill 2nd select
    Box2(0);
    }
    </script>
    
    </head>
    <body>
    <form name="myform" method="post" action="http://www.mysite.com/mysite">
    <fieldset><legend>fruit</legend>
    <select name="box1">
        <option value="a">apple</option>
        <option value="b">pear</option>
        <option value="c">orange</option>
    </select>
    <button type="submit">submit</button>
    </fieldset>
    </form>
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles