Changing items in aspx listbox from javascript

  • Thread starter Thread starter Jim M
  • Start date Start date
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
 
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
 
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.
 
Back
Top