In early day of my career I very often come
across setting a saved value in the server to a drop down list. So here is an
example which will helpful to you. Just copy past the below example and save the file as a sample.htm and check to see how it is working.
<HTML>
<HEAD>
<HTML>
<HEAD>
<TITLE>Javascript Eg.</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getValue() {
//In your case use the server tag here in place of "two" to retrieve the saved value it vary from one server to other server
var servervalue = "two";
for(var i=0; i<document.getElementById("ItemList").options.length; i++)
{
if ( document.getElementById("ItemList").options[i].text == servervalue )
{
document.getElementById("ItemList").selectedIndex = i;
break;
}
}
}
//Method 1.
//window.onload = getValue;
</SCRIPT>
</HEAD>
<!--Method 2.-->
<BODY onload="Javascript:getValue();">
<P>
Sample Dropdownlist
<SELECT NAME="ItemList">
<OPTION VALUE="one">one
<OPTION VALUE="two">two
<OPTION VALUE="three">three
<OPTION VALUE="four">four
</SELECT></P>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
function getValue() {
//In your case use the server tag here in place of "two" to retrieve the saved value it vary from one server to other server
var servervalue = "two";
for(var i=0; i<document.getElementById("ItemList").options.length; i++)
{
if ( document.getElementById("ItemList").options[i].text == servervalue )
{
document.getElementById("ItemList").selectedIndex = i;
break;
}
}
}
//Method 1.
//window.onload = getValue;
</SCRIPT>
</HEAD>
<!--Method 2.-->
<BODY onload="Javascript:getValue();">
<P>
Sample Dropdownlist
<SELECT NAME="ItemList">
<OPTION VALUE="one">one
<OPTION VALUE="two">two
<OPTION VALUE="three">three
<OPTION VALUE="four">four
</SELECT></P>
</BODY>
</HTML>
No comments:
Post a Comment