Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Every one,

I am assigning the value of the database column "PermState" to DropDownList1, so that it should appear as DropDownList1's SelectedIndex as given below:

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(dt.Rows[0]["PermState"].ToString().ToUpper()));



Here, I need to use a javascript to do the same instead of C# code.


Please any one give me a javascript for this.


Regards,
Posted
Updated 20-May-11 20:38pm
v3

1 solution

use below java script for dropdown selectedIndex.

pass the object instance (eg. comboBox1.clientID) either in server side or client side and the text witch u have to select..

I think this code will help you.


Example:

XML
<html>
<head>
<title>Customer Inquiry</title>
<SCRIPT language="JavaScript">
function setIndex(){
    var obj = document.getElementById('select');
    var YourText="MS"; // pass your text from here
    obj.selectedIndex= getIndexOnText(obj,YourText);
}
function getIndexOnText(obj ,YourText)
{
for(i=0; i < obj .length;i=i+1){
    matchText = obj .options[i].text;
    if(YourText == matchText){
        return i;
    }
        }
}
</SCRIPT>
</head>
<body>
    <form name="sysaccess" >
        <select name="select1" id="select">
        <option value="CL">CL</option>
        <option value="EL">EL</option>
   <option value="PS">PS</option>
   <option value="MS">MS</option>
   <option value="GS">GS</option>
        </select>
            <input type="button" onclick="setIndex()()">
    </form>
</body>
</html>
 
Share this answer
 
v3
Comments
Raj.rcr 25-May-11 2:48am    
Thanx a lot. I have got the clear idea and solved it.. my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900