Changing items in aspx listbox from javascript

J

Jim M

I am having trouble changing any properties of the web form listbox from
client side javascript.

As an example, all of the lines below seem to cause an error...

temp = document.getElementById("dropCategory1").length
window.alert("temp = " + temp)
document.getElementById("dropCategory1").Items.Clear()

Can the web form listbox be seen from client side javascript?

Thanks in advance.

Jim
 
S

Sean Bright

Yes, the problem is that the ID of the listbox changes once it is
rendered in the final output.

You can try something like this:

temp = document.getElementById("<%= dropCategory1.ClientID %>");

Which should give you the ID of the control once it has been rendered on
the page.

Thanks,
Sean
 
D

DWinter

You can, do it all the time, what is the error it is throwing?
I assume that you declared temp somewhere above this with var temp;
If not, try var temp=....
Eventhough they may not alway throw an error, use your semicolons as good
measure at the end of each line.
 

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

Top