In asp.net website, inside .aspx i have following code
<script type="text/javascript">
function callme(option) {
document.getElementById("t1").value = option;
}
</script>
<div id="content" runat="server"></div>
<input type="text" id="t1" />
On code behind file inside Page_Load:
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;
Whenever i select any option from dropdownlist it reflects its value inside the textbox t1. But at page load the textbox remains empty. I cannot use default value as the values of the dropdownlist are changing at runtime. How can I add first value of dropdownlist to textbox t1 on page load?