Subscribe to Subscribers
Talk to Webmaster Tony John


Forums » .NET » .NET »

javascript to set selected value of dropdown list box


Posted Date: 05 Apr 2006      Posted By:: narayanasamy durai     Member Level: Bronze    Member Rank: 0     Points: 2   Responses: 3



i have a dropdown list box it contain " A,B,C,D,E". And i have a textbox .

if i give " B " in text box ,the listbox value of " B " should become a selected value

pls if any body knew tel me

by durai




Responses

#46592    Author: ------      Member Level: Silver      Member Rank: 0     Date: 05/Apr/2006   Rating: 2 out of 52 out of 5     Points: 2

Type Only Capital letters in a text box

Its Only forHTML Controls


<form id="frm">
<input type="text" id="txt" name="txt" onkeyup="frmchng(this.value)">
<select id="slt"><option value=A>A</option>
<option value=B>B</option>
<option value=C>C</option>
<option value=D>D</option>
<option value=E>E</option>

</select>
</form>

<script language="javascript">
function frmchng(val)
{

for(i=0;i<document.all('slt').length;i++)
{


if(document.all('slt').options[i].value==val)
{
document.all('slt').selectedIndex=i

}


}


}
</script>



 
#46596    Author: Ramakrishna      Member Level: Gold      Member Rank: 575     Date: 05/Apr/2006   Rating: 2 out of 52 out of 5     Points: 2

<script language="javascript">
function fnSetDDL()
{
for(var i=0;i<=document.getElementById("DropDownList1").length-1;i=i+1)
{
var ddlText=document.getElementById("DropDownList1").options[i].outerText;
txtText=document.getElementById("TextBox2").value;
if(ddlText==txtText)
{
document.getElementById("DropDownList1").selectedIndex=i;
break;
}
}
}

</script>



private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack==false)
{
TextBox2.Attributes.Add("onkeyup","fnSetDDL();");
// bindDropDown();
}
}



 
#46597    Author: kedara      Member Level: Silver      Member Rank: 0     Date: 05/Apr/2006   Rating: 2 out of 52 out of 5     Points: 2

1.copy and paste the following in html page head section

<script language="javascript">

function setFocus()
{

var a=document.getElementById('TextBox1').value;
alert(a.toUpperCase());
for (i=0;i<document.getElementById('DropDownList1').length;i++)
{

if (a == document.getElementById('DropDownList1').options(i).text)
{
document.getElementById('DropDownList1').options(i).selected = true;
return;
}
}

}
</script>
2. in page_load()
TextBox1.Attributes("onblur") = "setFocus();"
3. execute






 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : what is difference between String and string(data type) in c#?
Previous : what is a resource file...
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.