Reputation: 304
I am trying to make my ASP:Listbox throw an event in javascript that will pick out the selected item and eventually will use that to choose what to do next. But with anything new, I always try and understand what is going on before I try and make it complex. I am able to get the javascript to connect to the listbox with the
document.getElementByID()
and the variable is populated with the items, but when I try and call on one of the items with
listbox.options[#].value
I get this error
"Microsoft JScript runtime error: 'listbox' is undefined"
Please help me figure out why I cant get to the information.
This is just to show a div that contains radio buttons, It is in "var index =" line that the error is occuring.
function showRadios() {
var listBox = document.getElementById('<%= lbxCheckListLevel3.ClientID %>');
var index = listbox.options[2].value;
if (listBox.Options[listBox.Options.SelectedIndex].text != null) {
var div = document.getElementById("radioDiv");
div.style.visibility = "visible";
}
Thanks in advance
EDIT: Is there any reason that the javascript wouldnt hold the information in the var? It seems that the variable isnt holding its own information. When changing the 2nd line of the code to
var index = listbox
I am still getting the same error, and no information is there when I mouse over it during a pause.
Upvotes: 0
Views: 1406
Reputation: 196187
Javascript is case-sensitive... so you will have a lot of corrections to do ..
function showRadios() {
var listBox = document.getElementById('<%= lbxCheckListLevel3.ClientID %>');
var index = listBox.options[2].value;
if (listBox.options[listBox.options.selectedIndex].text != null) {
var div = document.getElementById("radioDiv");
div.style.visibility = "visible";
}
Upvotes: 3