Sunday, January 2, 2011

Textual description of firstImageUrl

Search ListBox items using JavaScript

Technorati Tags: ,,,,
This example shows how to select ListItems in the ListBox based from the TextBox values using JavaScript.
Its only select the first letter in list box control .If you want to filtering check this Filtering Listbox control using Javascript.

Here’s the code block below.
<html xmlns="" >
<head id="Head1" runat="server">
<script type="text/javascript" language="javascript">
function SearchList()
var l = document.getElementById('<%= ListBox1.ClientID %>');
var tb = document.getElementById('<%= TextBox1.ClientID %>');
if(tb.value == "")
for (var i=0; i < l.options.length; i++)
if (l.options[i].text.toLowerCase().match(tb.value.toLowerCase()))
l.options[i].selected = true;
return false;
function ClearSelection(lb)
lb.selectedIndex = -1;
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" onkeyup="return SearchList();"/><br />
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="250px">
The JavaScript function basically searches the ListBox items and find the items based from the value of the TextBox that was entered. If a keyword exist from the list then it will automatically select the ListItems in the ListBox, but if the keyword does not exist then it will clear the ListBox selection.
See the output below when you run it on the page

1 comment:

PDF Arabic watermark using MVC and iTextSharp

PDF full page Arabic watermark using MVC and iTextSharp Download :  Source Code Most of the time we have requirement to  gen...