home *** CD-ROM | disk | FTP | other *** search
/ PC User 2005 May / CD / PCU0505CD.iso / software / full / coffecup / files / html2005.exe / %MAINDIR% / Javascript / search-drop-down-list.xml < prev    next >
Encoding:
Text File  |  2005-02-16  |  1.8 KB  |  85 lines

  1.  
  2. <ccresource>
  3.   <cctitle>
  4. Drop Down List Search
  5.   </cctitle>
  6.   <cccategory>
  7. Browser
  8.   </cccategory>
  9.   <ccDescription>
  10.     This code will allow the visitor to search a drop down box listing. Perfect for those who have very long lists.
  11.   </ccdescription>
  12.   <ccinstructions>
  13.   The code goes both within the HEAD and BODY tags.  You can change the items in the dropdown menu to suit your needs.
  14.   </ccinstructions>
  15.   <ccheadcontent>
  16. <SCRIPT LANGUAGE="JavaScript">
  17.  
  18. <!-- Begin
  19. function promptSearch (thisform, thisfield) {
  20. var elnum = parseInt(-1);
  21. var k = parseInt(-1);
  22. for (var j = 0; j < document.forms[thisform].elements.length; j++) {
  23. if (document.forms[thisform].elements[j].name == thisfield) {
  24. elnum = j;
  25. break;
  26.    }
  27. }
  28. var myvar = "";
  29. var srch = "";
  30. var menuLength = "";
  31. menuLength = eval("document." + thisform + "." + thisfield + ".length");
  32. srch = prompt("Search this drop down menu for...", "");
  33. if (srch ) {
  34. srch = srch.toUpperCase();
  35. for (var i = 0; i < menuLength; i++) {
  36. myvar = eval("document." + thisform + "." + thisfield + ".options[" + i + "].text.toUpperCase()");
  37. if (myvar.indexOf(srch) >= 0) {
  38. document.forms[thisform].elements[elnum].options[i].selected = true;
  39. break;
  40.       }
  41.    }
  42. }
  43. return false;
  44. }
  45. //  End -->
  46. </script>
  47.   </ccheadcontent>
  48.   <ccbodycontent>
  49.  
  50.  
  51. <center>
  52. <form name=myform action="">
  53. <select name=menu1 size=1 onFocus="promptSearch(this.form.name, this.name)">
  54. <option>a1
  55. <option>a2
  56. <option>a3
  57. <option>a4
  58. <option>a5
  59. <option>a6
  60. <option>a7
  61. <option>a8
  62. <option>a9
  63. <option>a10
  64. <option>a11
  65. <option>a12
  66. <option>a13
  67. <option>a14
  68. <option>a15
  69. </select>
  70. </form>
  71. </center>
  72.  
  73.  
  74.   </ccbodycontent>
  75.   <ccelementcontent>
  76.   
  77.    <ccelementname></ccelementname>
  78.    <ccelementaction></ccelementaction>
  79.    
  80.   </ccelementcontent>
  81.   <ccextradata>
  82.  
  83.   </ccextradata>
  84. </ccresource>
  85.