472,143 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 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 12655
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 leo001 | last post: by

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.