473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

adding items to a listbox using clientside javascript

I need to be able to dynamically add items to a <asp:listbox> (or HTML
<select runat=server>) using clientside javascript, and retrieve the items
when the page is posted back.

I use this code to add the option to the listbox. It works for <select> or
<asp:listbox> controls.

var opt = document.CreateElement("OPTION");
opt.text = "test";
opt.value="test";
window.document.getElementByID("listName").options .add(opt);

I have no problem adding the items to the listbox, but they are not posted
to the server on postback.

When the page posts back, the listbox control has no items.

Is there something I can do to make these added items accessible when the
page posts back?

Thanks
Bill


Jun 16 '06 #1
1 12731
the browser only posts back the value of the selected option, not the
complete option list. you will need to store the option list values in a
hidden field(s) that are included with the postback.

-- bruce (sqlwork.com)

"bill" <be****@datamti.com> wrote in message
news:el**************@TK2MSFTNGP02.phx.gbl...
I need to be able to dynamically add items to a <asp:listbox> (or HTML
<select runat=server>) using clientside javascript, and retrieve the items
when the page is posted back.

I use this code to add the option to the listbox. It works for <select>
or <asp:listbox> controls.

var opt = document.CreateElement("OPTION");
opt.text = "test";
opt.value="test";
window.document.getElementByID("listName").options .add(opt);

I have no problem adding the items to the listbox, but they are not posted
to the server on postback.

When the page posts back, the listbox control has no items.

Is there something I can do to make these added items accessible when the
page posts back?

Thanks
Bill

Jun 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CJM | last post by:
I would like to be able to use an autocompleting listbox - that is, one where you can select an item in the list by typing the first few characters; the standard IE listbox only responds to the...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
1
by: Brian Henry | last post by:
I haven't worked with java script much, I know how to do this server side by constant post backs to the server on a webform, but it seems like i should be able to do this client side also... ...
4
by: Henrik Holle | last post by:
Hi, i have a serverside listbox but i modify the value with javascript on the clientside. On postback my changed/added values are all lost? what am i doing wrong? Is it not possible to change...
3
by: Ryan Taylor | last post by:
Hello. I have an application where I need the user to be able to add items to a listbox. I've implemented this via javascript. The listbox is an <asp:ListBox>. However, when the user submits the...
1
by: RFS666 | last post by:
Hello together, I wanted to ask if somebody can help me with accessing a listbox (a serverside webform from the designer-toolbox) from clientside JScript. I need to add and remove values and...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.