Fetch value from dropdown into a text box using javascript
-
1. Used ASP.NET controls: dropdown and textbox. 2. For the 1st time at page load, some default values should be populated in dropdown and 1st value in text box. Written the below code protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.Items.Add("a"); DropDownList1.Items.Add("b"); DropDownList1.Items.Add("c"); TextBox1.Text = DropDownList1.SelectedValue; } } 3. Set the autopostback of dropdown=False. So "DropDownList1_SelectedIndexChanged1" will not work. I have done this because after selecting any value in dropdown, post back should not take place. 4. Now we have values in drop down. I want to select a value in dropdown and same selected value should be visible in text box. I want a java script for this. Not able to write it as not able to find any client event for dropdown. Actually there is event "onclientclick" for an asp.net button control, but did not find any such event for dropdown. So how to write java script code.
-
1. Used ASP.NET controls: dropdown and textbox. 2. For the 1st time at page load, some default values should be populated in dropdown and 1st value in text box. Written the below code protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.Items.Add("a"); DropDownList1.Items.Add("b"); DropDownList1.Items.Add("c"); TextBox1.Text = DropDownList1.SelectedValue; } } 3. Set the autopostback of dropdown=False. So "DropDownList1_SelectedIndexChanged1" will not work. I have done this because after selecting any value in dropdown, post back should not take place. 4. Now we have values in drop down. I want to select a value in dropdown and same selected value should be visible in text box. I want a java script for this. Not able to write it as not able to find any client event for dropdown. Actually there is event "onclientclick" for an asp.net button control, but did not find any such event for dropdown. So how to write java script code.
-
Perhaps he cares about writing efficient code that is scalable ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.