Within my asp.net website, in the .aspx file, the following code is present:
<script type="text/javascript">
function callme(option) {
document.getElementById("t1").value = option;
}
</script>
<div id="content" runat="server"></div>
<input type="text" id="t1" />
In the code behind file within the Page_Load method:
content.InnerHtml = MyClassObject.MyMethod(...);
Inside MyClass:
public String MyMethod(...)
{
... //some code
String str1 ="<select id=\"s1\" onchange=\"callme(this.value)\">" +
" <option value=\"1\">One</option>"+
" <option value=\"2\">Two</option>" +
" <option value=\"3\">Three</option>" +
"</select>";
... // some code
return str1;
Even though selecting an option from the dropdownlist updates the textbox t1 with its value, the textbox remains empty on page load. Since the dropdownlist values are dynamic, how can I automatically set the value of the first option in the dropdownlist to be displayed in the textbox t1 upon page load?