Hello, Do you know how to create a form with three drop-down fields - the second depends on the first and the third depends on the first too. Could somebody help me? Thank you
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Any Title</title> <script type="text/javascript"> var categories = []; categories["startList"] = ["Apparel","Books"] categories["Apparel"] = ["Men","Women"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Men"] = ["Shirts","Ties","Belts"]; categories["Women"] = ["Blouses","Skirts","Scarves"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science","Romance"]; categories["Nonfiction"] = ["How-To","Travel","Cookbooks"]; var nLists = 3; // number of lists in the set function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms[0]['List'+i].length = 1; document.forms[0]['List'+i].selectedIndex = 0; } var nCat = categories[currCat]; for (each in nCat) { var nOption = document.createElement('option'); var nData = document.createTextNode(nCat[each]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(isValue){ alert(isValue); } function init(){ fillSelect('startList',document.forms[0]['List1']) } onload=init; </script> <style type="text/css"> body {margin-top: 65px;} form {width:425px; margin:auto;} </style> </head> <body> <form action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <select name='List3' onchange="getValue(this.value)"> <option selected >Make a selection</option> </select> </form> </body> </html> Code (markup):
normally they are called cascading drop downs. You can do it with javascript or ajax subject to the number of options that are going to be in the final drop down
normally they are called cascading drop downs. You can do it with javascript or ajax subject to the number of options that are going to be in the final drop down