469,592 Members | 1,698 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

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 12553
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John R. | last post: by
4 posts views Thread by Henrik Holle | last post: by
3 posts views Thread by Ryan Taylor | last post: by
14 posts views Thread by Paul_Madden via DotNetMonster.com | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.