How to get selected listbox item and copy it to a text box control using Java Script.
I have an Asp.net listbox on a web form. Below that is a text box control. When I select an item from the listbox, I would like Java Script to take the selected text in the listbox and then copy it into the text box control. Can someone show me how to do this?
I am using Asp.net with C#, however I need to use Java Script to prevent postback flash. Ajax is not an option right now. Only Java Script. Can someone help me out?
ASP.NET
Last Comment
brgdotnet
8/22/2022 - Mon
Nathan Bove
Just an FYI, this really isn't an ASP.NET question, it is a javascript question and you would probably get better results if you posted in the correct area. That being said, I think you can accomplish what you want with the following code:
Hi nbove. I can't get your code to work. Your code does not work.
I have been working with various Java Script and can't get it to work with Asp.net listboxes. I think with Asp.net the listbox working with Java Script is different then just your typical listbox control. So I think the question should remain in Asp.net since the Java Script needs to work with the listbox control.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
<asp:ListBox ID="MyListBox" runat="server" onchange="ListBoxChanged(t
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
</asp:ListBox>
<asp:TextBox ID="MyTextBox" runat="server">
<script type="text/javascript">
function ListBoxChanged(listBox) {
document.getElementById('<
}
</script>