accessing webforms-listbox from clientside jscript

G

Guest

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 find out about the selected index.

I hope somebody can help & thanks in advance

RFS666
 
G

Guest

To add a value (listitem):
var list = document.getElementById ("ListBox1");
if (list)
{
alert("selected Index= " + list.selectedIndex;
var option= document.createElement ("option");
list.options.appendChild(option);
var txt = document.getElementById ("txtListItem");
option.text=txt.value;
}

The ListBox server control renders an HTML select object on the browser. To
manipulate it using JScript (or Javascript) use the options collection of the
HTML SELECT object. There is a "remove" method for the options collection.

For a sample on managing the viewstate of ListBox server control on the
browser: http://www.societopia.net/samples/listbox_clientside.aspx
 

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

Forum statistics

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

Latest Threads

Top