www.webdeveloper.com
Results 1 to 2 of 2

Thread: Fill Drop Down Based On Another Drop Down Selection

  1. #1
    Join Date
    Mar 2006
    Posts
    1

    Fill Drop Down Based On Another Drop Down Selection

    Hello,

    I need help with js code that will fill a drop down based on another drop down selection. This is what I am working on...

    http://www.santanprintwear.com/template.htm

    Basically, not all colors come in all sizes. So I need the "Choose Color" drop down to autofill after a selection is made in my "Choose Size" drop down.

    I would appreciate any help. Be easy on me I am GREEN GREEN GREEN

    Thanks,
    Darla

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>Change selection in one box from another</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(i=0; i<varieties[idx].length; i++) {
        f.box2.options[i]=new Option(varieties[idx][i], i); 
        }    
    }
    
    onload=function() {Box2(0);};
    </script>
    </head>
    <body>
    <form name="myform" method="post" action="#">
    <div>
    <select name="box1" onchange="Box2(this.selectedIndex)">
        <option value="a">apple</option>
        <option value="b">pear</option>
        <option value="c">orange</option>
    </select>
    <select name="box2"></select>
    </div>
    </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