Monday, June 9, 2008

how to search textbox value in dropdownlist Using Javascript

<asp:TextBox ID="txtbox" runat="server" onkeyup="getValue(this)"></asp:TextBox>
<asp:DropDownList ID="drpt" runat="server">
<asp:ListItem Text="text">ss</asp:ListItem>
<asp:ListItem Text="text">ss1</asp:ListItem>
<asp:ListItem Text="text">ss2</asp:ListItem>
<asp:ListItem Text="text">ss3</asp:ListItem>
<script language="javascript">

function getValue(obj)
{
var d=obj.value;
var dro=document.getElementById("drpt");
var drplen=document.getElementById("drpt").options.length
var i;
for(i=0;i<drplen;i++)
{
if(document.getElementById("drpt").options[i].value==d)
{
document.getElementById("drpt").selectedIndex=i;
}
}
}
</asp:DropDownList>

</script>