0

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.

1 Answer 1

3

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";
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, case isnt the problem here. I have played with the cases plenty. Sorry if my question was a little bit confusing with the problem line, but its the line that index gets set, not the 'if' statement
@Seige, on that line too, you have listbox while it should be listBox (capital B)
WOW!!! HOW THE !@#$ DID I NOT SEE THAT?? when you said case sensitive i was looking at the spelling of that word aswell. Appologies. and thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.