SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    ny
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Global variable unrecognized by window.ONLOAD?

    I code my global variables first,
    then my window.onload function, like this:
    Code:
    var globvar = {
      oneTimeSwitch: "0",	
      kbinput: document.createElement("INPUT"),
      kbdivision: document.createElement("DIV"),
    etc.
    }
    
    window.onload = function() {
      if (kbinput==undefined) alert("NO KBINPUT!!!!");
      setTriggers();
    }
    Why does this code generate this error:
    "kbinput is not defined"?
    Or, I suppose it's the same question,
    why doesn't the if statement for undefined element
    catch the problem?

  2. #2
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code:
    if (!window.kbinput) alert("NO KBINPUT!!!!");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •