Copy Code code as follows:
<script Language=jscript type=text/javascript>
var Isopera = navigator.userAgent.indexOf ("Opera") >-1;
var Isie = navigator.userAgent.indexOf ("MSIE") > 1 &&!isopera;
var Ismoz = navigator.userAgent.indexOf ("MOZILLA/5.") = = 0 &&!isopera;
function Textboxselect (Otextbox, IStart, iend) {
Switch (arguments.length) {
Case 1:
Otextbox.select ();
Break
Case 2:
Iend = OTextbox.value.length;
/* Falls through * *
Case 3:
if (Isie) {
var oRange = Otextbox.createtextrange ();
Orange.movestart ("character", IStart);
Orange.moveend ("character",-otextbox.value.length + iend);
Orange.select ();
else if (Ismoz) {
Otextbox.setselectionrange (IStart, iend);
}
}
Otextbox.focus ();
}
/*
function Textboxreplaceselect (Otextbox, stext) {
if (Isie) {
var oRange = Otextbox.createtextrange ();
Orange.text = Stext;
Orange.collapse (TRUE);
Orange.select ();
else if (Ismoz) {
var iStart = Otextbox.selectionstart;
Otextbox.value = oTextbox.value.substring (0, IStart) + stext + oTextbox.value.substring (otextbox.selectionend, OTextbox.value.length);
Otextbox.setselectionrange (IStart + stext.length, IStart + stext.length);
}
Otextbox.focus ();
}
*/
function Autocompletematch (stext, arrvalues) {
for (Var i=0 i < arrvalues.length; i++) {
if (Arrvalues[i].indexof (stext) = = 0) {
return arrvalues[i];
}
}
return null;
}
Function AutoComplete (Otextbox, oevent, arrvalues) {
Switch (oevent.keycode) {
Case://up Arrow
Case://down Arrow
Case://left Arrow
Case://right Arrow
Case://page up
Case://page Down
Case://home
Case://end
Case://enter
Case 9://tab
Case://esc
Case://shift
Case://ctrl
Case://alt
Case://caps Lock
Case 8://backspace
Case://delete
return true;
Break
Default
The following line is not very useful (annotated)
Textboxreplaceselect (Otextbox, Isie otextbox.value/*oevent.keycode*/: Oevent.charcode);
var ilen = oTextbox.value.length;
var smatch = Autocompletematch (Otextbox.value, arrvalues);
if (Smatch!= null) {
Otextbox.value = Smatch;
Textboxselect (Otextbox, Ilen, oTextbox.value.length);
}
return false;
}
}
</SCRIPT>
<SCRIPT>
var arrvalues = ["Red", "orange", "Yellow", "green", "Blue", "Indigo", "Violet", "Brown"];
</SCRIPT>
<p>type in a-color in lowercase: Enter a color that starts with a lowercase letter (English words, such as: R, B, etc.) <br><input id=txt1 onkeyup= "return AutoComplete (This, event, arrvalues) "></P>