By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,368 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,368 IT Pros & Developers. It's quick & easy.

adding items to a listbox using clientside javascript

P: n/a
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
Share this Question
Share on Google+
1 Reply

P: n/a
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.