adding items to a listbox using clientside javascript

B

bill

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
 
B

bruce barker \(sqlwork.com\)

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top