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: 572     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.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India