Saturday, March 24, 2012

populate listbox using Javascript

I tried following :
document.getElementById("lsTest").Items.Add(new ListItem("Test"))
This gives following error message:
'document.getElementById(...).Items' is null or not an object
Also tried:
document.getElementById("lsTest").Add(new ListItem("Test"))
Result - Error Message:
'listitem' is undefined
Any idea?var o = document.createElement("option");
o.text = "test"
o.value = "test";
document.getElementById("lsTest").add(o);
-- bruce (sqlwork.com)
"RA" <rchaudhary-nospam@.storis.com> wrote in message
news:%23IOtEyPyEHA.2016@.TK2MSFTNGP15.phx.gbl...
| I tried following :
| document.getElementById("lsTest").Items.Add(new ListItem("Test"))
|
| This gives following error message:
| 'document.getElementById(...).Items' is null or not an object
|
| Also tried:
| document.getElementById("lsTest").Add(new ListItem("Test"))
| Result - Error Message:
| 'listitem' is undefined
|
| Any idea?
|
|
Hi RA,
you can not add a listitem from javascript. A ListBox is rendered as
html SELECT element. So, you should add the items in javascript as if you
are adding to a SELECT element, which would be like follows
document.getElementById("lsTest").add(new Option("Text","Value"));
HTH
Kumar
"RA" <rchaudhary-nospam@.storis.com> wrote in message
news:%23IOtEyPyEHA.2016@.TK2MSFTNGP15.phx.gbl...
> I tried following :
> document.getElementById("lsTest").Items.Add(new ListItem("Test"))
> This gives following error message:
> 'document.getElementById(...).Items' is null or not an object
> Also tried:
> document.getElementById("lsTest").Add(new ListItem("Test"))
> Result - Error Message:
> 'listitem' is undefined
> Any idea?
>
To remove an item from a textbox I tried;
document.getElementById("lsTest").remove(new Option("Testing","Testing"));
and
document.getElementById("lsTest").remove("Testing");
neither of above work. Both deletes very first Item in the listbox.
What I am doing wrong?
"Kumar Reddi" <KumarReddi@.REMOVETHIS.gmail.com> wrote in message
news:Odz5c8PyEHA.3096@.tk2msftngp13.phx.gbl...
> Hi RA,
> you can not add a listitem from javascript. A ListBox is rendered as
> html SELECT element. So, you should add the items in javascript as if you
> are adding to a SELECT element, which would be like follows
> document.getElementById("lsTest").add(new Option("Text","Value"));
> HTH
> Kumar
> "RA" <rchaudhary-nospam@.storis.com> wrote in message
> news:%23IOtEyPyEHA.2016@.TK2MSFTNGP15.phx.gbl...
>

0 comments:

Post a Comment