Начало
Формы
Поиск выбора
В нашем примере ищите ценность между 'a1' и 'a15'.
a1
a2
a3
a4
a5
a6
a7
a8
a9
a10
a11
a12
a13
a14
a15
JavaScript Forms: Поиск выбора
<!-- TWO STEPS TO INSTALL OPTION SEARCH: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- Begin function promptSearch (thisform, thisfield) { var elnum = parseInt(-1); var k = parseInt(-1); for (var j = 0; j < document.forms[thisform].elements.length; j++) { if (document.forms[thisform].elements[j].name == thisfield) { elnum = j; break; } } var myvar = ""; var srch = ""; var menuLength = ""; menuLength = eval("document." + thisform + "." + thisfield + ".length"); srch = prompt("Search this menu for...", ""); if (srch ) { srch = srch.toUpperCase(); for (var i = 0; i < menuLength; i++) { myvar = eval("document." + thisform + "." + thisfield + ".options[" + i + "].text.toUpperCase()"); if (myvar.indexOf(srch) >= 0) { document.forms[thisform].elements[elnum].options[i].selected = true; break; } } } return false; } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <center> <form name=myform action=""> <select name=menu1 size=1 onFocus="promptSearch(this.form.name, this.name)"> <option>a1 <option>a2 <option>a3 <option>a4 <option>a5 <option>a6 <option>a7 <option>a8 <option>a9 <option>a10 <option>a11 <option>a12 <option>a13 <option>a14 <option>a15 </select> </form> </center> <!-- Script Size: 1.90 KB -->