Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Populating an ASP.NET label with a selection made from a ListBox using a client script. (JavaScript, etc.)

I have a label called Label1 and a Listbox called ListBox1 on an ASP.NET web form.
I am populating Listbox1 with 4 options on the page load event in my code behind.
When the selection in Listbox1 changes, I want this change to be reflected in Label1 by assigning the text value of Label1 to the selection.
I want this action to be performed on the client side only.

How?
TIA
Avatar of leakim971
leakim971
Flag of Guadeloupe image

with firefox, do a right on your Listbox1, choose inspect element and post the HTML for this listbox1 here.
else just post the whole body part.
Avatar of Member_2_1242703
Member_2_1242703

ASKER

How about I just post my code so far...

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test2.aspx.vb" Inherits="Diamond_Group.test2" %>
<!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>
        <asp:Label ID="Label1" runat="server" Text="blahblah"></asp:Label>
        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
        <br />
    </div>
    </form>
</body>
</html>

Open in new window


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ListBox1.Items.Add("option 1")
            ListBox1.Items.Add("option 2")
            ListBox1.Items.Add("option 3")
            ListBox1.Items.Add("option 4")
            ListBox1.Items.Add("option 5")
            ListBox1.Items.Add("option 6")
        End If
    End Sub

Open in new window

hmmm my comment was clear : with firefox, do a right on your Listbox1, choose inspect element
you can use chrome too or a recent internet explorer
<select size="4" name="ListBox1" id="ListBox1">
      <option value="option 1">option 1</option>
      <option value="option 2">option 2</option>
      <option value="option 3">option 3</option>
      <option value="option 4">option 4</option>
      <option value="option 5">option 5</option>
      <option value="option 6">option 6</option>

</select>
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, thank you.