JSP matches the drop-down box option based on the input content

Source: Internet
Author: User
<% @ Page contenttype = "text/html; charset = gb2312" %>
<HTML>
<Head>
<Title> matching options based on input </title>
</Head>
<Script language = "JavaScript">
<! --
VaR whichtext;
Function selectstation (OBJ ){
VaR objselstation = OBJ;
If (obj. selectedindex! =-1 ){
VaR stationname = obj. Options [obj. selectedindex]. text;
Whichtext. value = stationname;
}
Showdivstation (this, false, 'selstation ') // click an option and close the drop-down box.
}

// Response to the text event
VaR paged = 0, pageu;
Function similarfind (txtobj, seledname ){
VaR curstationname = txtobj. value;
VaR objselstation = eval ("document. myform." + seledname); // modify it based on the actual form name
VaR stationlength = objselstation. Options. length;
Pageu = paged;

// Match the data in text with the data in the drop-down box
For (VAR I = 0; I <stationlength; I ++ ){
VaR stationname = objselstation. Options [I]. text;
VaR Re = new Regexp ("^" + curstationname );
If (stationname. Match (re )){
If (I <stationlength-10 ){
Objselstation. selectedindex = I + 10;
}
Objselstation. selectedindex = I;
Paged = I;
Pageu = I;
Break;
}
}
// Response move down key
If (event. keycode = 40 ){
Paged ++;
If (Paged = objselstation. Options. Length) paged = 0;
Txtobj. value = objselstation. Options [paged]. text;
Objselstation. selectedindex = paged;
}
// Response to the move-up key
If (event. keycode = 38 ){
-- Pageu;
If (pageu <0) pageu = objselstation. Options. Length-1;
Txtobj. value = objselstation. Options [pageu]. text;
Objselstation. selectedindex = pageu;
}
}
// Position displayed in the drop-down list
Function showdivstation (OBJ, B, selname ){
VaR divstation = eval ("document. myform." + selname); // modify according to the actual form name
If (B ){
Whichtext = OBJ;
Divstation. style. Top = 20;
Divstation. style. Left = 0;
Divstation. style. Display = "Block ";
Similarfind (OBJ, selname );
} Else {
Divstation. style. Display = "NONE ";
}
}
// -->
</SCRIPT>
<Body bgcolor = "# ffffff" topmargin = "0" leftmargin = "0">
<Form name = "myform">
<Table border = "0" style = "border-collapse: collapse" bordercolor = "#111111" width = "100%" id = "autonumber1">
<Tr>
<TD width = "6%" valign = "TOP"> city </TD>
& Lt; TD width = "94%" bgcolor = "# ffffff" & gt;
<! -- When onfocus is used to obtain the focus, the onkeyup dialog box pops up and press the up/down key to move in the drop-down list. -->
<Input type = "text" size = "70" name = "put" style = "width: 120" onfocus = "showdivstation (this, true, 'selstation ') "onkeyup =" similarfind (this, 'selstation ') "value =" ">
<! -- Select option when onclick is clicked -->
<Select name = "selstation" size = "6" style = "display: none; width: 120;" onclick = "selectstation (this)">
<Option value = "BJ"> Beijing </option>
<Option value = "SD"> Shandong </option>
<Option value = "SX"> Shanxi </option>
<Option value = "heb"> Hebei </option>
<Option value = "inherit"> Henan </option>
<Option value = "Hub"> Hubei </option>
<Option value = "hun"> Hunan </option>
<Option value = "GD"> Guangdong </option>
<Option value = "GX"> Guangxi </option>
</SELECT>
</TD>
</Table>
</Form>
</Body>
</Html>

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.