1

Greetings,

I'm trying to select item from asp.net list box then assign it to a text box so when a click on an item from the list box should appear in the text box.

I tried the code listed down but it did not work. please advice how to do this!!

............................ updated code ..........................

  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="IMAM_APPLICATION.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <script src="js/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>

    <script src="js/jquery.validate.js" type="text/javascript"></script>

       <script type="text/javascript">
           $(function() {
               $("#<%=ListBox.ClientID %>").change(function() {
                   $("#<%=text.ClientID %>").val($(this).val());
               });
           });


    </script>


<asp:ListBox ID="ListBox" runat="server">

 <asp:ListItem Value="one">1</asp:ListItem>
 <asp:ListItem Value="two">2</asp:ListItem>

</asp:ListBox>

<asp:TextBox ID="text" runat="server" 
            style = "position:absolute; top: 267px; left: 45px;"></asp:TextBox>
    </div>
    </form>
</body>
</html>

1 Answer 1

1

You can do it like this:

$(function() {
  $("#<%=ListBox.ClientID %>").change(function() {
    $("#<%=text.ClientID %>").val($(this).val());
  });
});

Replace your $(document).ready(function() { }) with the above code, and when you change the dropdown, the value will go in the text input, e.g. one, or two.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your reply. there is a problem that I need to click the text box after I select an item from listbox to see it appear in the text box. please advice how to solve this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.