majed

casecading

Apr 29th, 2011
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //this code from this page
  2.  
  3. http://www.codingforums.com/showthread.php?t=202456
  4. <html>
  5. <head>
  6.  
  7. <script type="text/javascript">
  8.  
  9. var categories = [];categories["startList"] = ["Apparel","Books"]
  10. categories["Apparel"] = ["Men","Women"];
  11. categories["Books"] = ["Biography","Fiction","Nonfiction"];
  12. categories["Men"] = ["Shirts","Ties","Belts"];
  13. categories["Women"] = ["Blouses","Skirts","Scarves"];
  14. categories["Biography"] = ["Contemporay","Historical","Other"];
  15. categories["Fiction"] = ["Science","Romance"];
  16. categories["Nonfiction"] = ["How-To","Travel","Cookbooks"];
  17.  
  18. var nLists = 3; // number of lists in the set
  19.  
  20. function fillSelect(currCat,currList){
  21. var step = Number(currList.name.replace(/\D/g,""));
  22. for (i=step; i<nLists+1; i++) {
  23. document.forms[0]['List'+i].length = 1;
  24. document.forms[0]['List'+i].selectedIndex = 0;
  25. }
  26. var nCat = categories[currCat];
  27. for (each in nCat)  {
  28. var nOption = document.createElement('option');
  29. var nData = document.createTextNode(nCat[each]);
  30. nOption.setAttribute('value',nCat[each]);
  31. nOption.appendChild(nData);
  32. currList.appendChild(nOption);
  33. }
  34. }
  35.  
  36. function getValue(isValue) {
  37. alert(isValue);
  38. }
  39.  
  40. function init() {
  41. fillSelect('startList',document.forms[0]['List1'])
  42. }
  43.  
  44. navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);   
  45.  
  46. </script>
  47. </head>
  48.  
  49. <body>
  50. <form action="">
  51. <select name='List1' onchange="fillSelect(this.value,this.form['List2'])">
  52. <option selected>Make a selection</option>
  53. </select>
  54. &nbsp;
  55. <select name='List2' onchange="fillSelect(this.value,this.form['List3'])">
  56. <option selected>Make a selection</option>
  57. </select>
  58. &nbsp;
  59. <select name='List3' onchange="getValue(this.value)">
  60. <option selected >Make a selection</option>
  61. </select>
  62. </form>
  63.  
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment