ASP. NET automatically locates items in ListBox according to the input content of TextBox.

Source: Internet
Author: User

This effect is very simple.
[Javascript]
<Script type = "text/javascript">
 
Function OnTextChanged (textBoxID, listBoxID ){
Var inputText = $. trim ($ ("#" + textBoxID. toString (). val ());
If (inputText. length! = 0 ){
For (var I = 0; I <document. getElementById (listBoxID. toString (). options. length; I ++ ){
Document. getElementById (listBoxID). options [I]. selected = false;
}
 
Var sInputName = inputText. toUpperCase ();
Var iStopFlag =-1;
Var iIndex = 0;
Var sText;
While (iIndex <document. getElementById (listBoxID). options. length & iStopFlag =-1 ){
SText = document. getElementById (listBoxID). options [iIndex]. text. toUpperCase ();
If (sText. indexOf (sInputName )! =-1 ){
Document. getElementById (listBoxID). options [iIndex]. selected = true;
// IStopFlag = 0;
}
IIndex ++;
}
}
}

</Script>

Front-end code:
[Html]
<Table>
<Tr>
<Td>
<Div style = "margin-top: 0; text-align: right">
Locate the merchant (enter the merchant name ):
<Asp: TextBox ID = "txtLocateAllSeller" runat = "server" onkeyup = "OnTextChanged ('txtlocateallseller ', 'liboxallsellers')"> </asp: TextBox> </div>
</Td>
<Td>
</Td>
<Td>
<Div style = "margin-top: 0; text-align: left">
Locate the merchant (enter the merchant name ):
<Asp: TextBox ID = "txtLocateSelectSeller" runat = "server" onkeyup = "OnTextChanged ('txtlocateselectseller ', 'selectsellers')"> </asp: TextBox> </div>
</Td>
</Tr>
</Table>
The advantage of this js method is a general method. You only need to input the TextBox ID and ListBox ID. Location is also equivalent to fuzzy query.


Author: Chinajiyong

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.