<html>
<head>
<meta http-equiv= "Content-type content=" HTML; charset=gb2312 ">
<meta content= "Fason, a letter" name=author>
<title>js dynamic hint dropdown box </title>
<style>
a{color:red;text-decoration:none;font-size:12px}
</style>
</head>
<body onload= "Init ()" >
<center>
<h2>js dynamic hint dropdown box </h2>
<hr>
<form name=frm>
<table>
<tr>
<td> Please enter 1 or 2 or 3 or 4 or 5 to test: <br><input name= "txt" style= "width:100px" onkeyup= "Selecttip (0)" > < Input type= "button" value= "reset" onclick= "Selecttip (1)" ></td>
</tr>
<tr>
<td>
<span id= "Demo" ><select name= "demo" style= "width:100px" size=10 onchange= "Txt.value=options[selectedindex" . text; >
<option value= "1" >1</option>
<option value= "a" >12</option>
<option value= "123" >123</option>
<option value= "1234" >1234</option>
<option value= "2" >2</option>
<option value= >23</option>
<option value= "234" >234</option>
<option value= "2345" >2345</option>
<option value= "3" >3</option>
<option value= >34</option>
<option value= "345" >345</option>
<option value= "3456" >3456</option>
<option value= "5" >5</option>
<option value= "Wuyi" >51</option>
<option value= "51w" >51w</option>
<option value= "51wi" >51wi</option>
<option value= "51win" >51win</option>
<option value= "51windows" >51windows</option>
</select></span>
</td>
</tr>
</form>
</table>
<hr>
<script language= "JavaScript" >
var temparr=[];//storage Option
function Init () {
var selectobj=document.frm.elements["Demo"]
/* First store the data in an array * *
With (Selectobj)
for (i=0;i<length;i++) Temparr[i]=[options[i].text,options[i].value]
}
Function Selecttip (flag) {
var txtobj=document.frm.elements["txt"]
var Selectobj=document.getelementbyid ( "Demo")
var arr=[]
with (selectobj) {
var selecthtml=innerhtml.match (/<[^>]*>/) [0]
for (i=0;i<temparr.length;i++)
if (Temparr[i][0].indexof (txtobj.value) ==0| | Flag)//if found with the content of txt beginning, add option. If flag is true, initializes the
arr[arr.length]= <option value= ' +temparr[i][1]+ ' > ' +temparr[i][0]+ ' to the dropdown box </ Option> "
innerhtml=selecthtml+arr.join () +" </SELECT> "
}
}
</script>
</ Body>