Topic: My global variable - why is it undefined? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: |
![]() I code my global variables first, code: var globvar = { oneTimeSwitch: "0", kbinput: document.createElement("INPUT"), kbdivision: document.createElement("DIV"), etc. } window.onload = function() { if (kbinput==undefined) alert("NO KBINPUT"); setTriggers(); }
|
Paranoid (IV) Inmate From: Norway |
![]() |
Nervous Wreck (II) Inmate From: United States |
![]() As poi said, kbinput is undefined because you never defined it. The reason you received the error rather than seeing "NO KBINPUT", however, is because you can't check for undefined global variables using the == operator unless you check them in terms of the window object. E.x. kbinput==undefined throws an error, but window.kbinput==undefined would show your error message. Object properties need not be prepended with "window.", however -- globvar.kbinput==undefined would work just fine. |
Nervous Wreck (II) Inmate From: |
![]() Edit TP: spam removed
|