JS Dynamic hint dropdown box

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax content document html http javascript name select

<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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.