title: Body onload in Javascript
body: <p>I had written one JS in asp.net. I had called that from body <code>onload</code>, but the JS doesn't get called where I have put my debugger. What could be possible reasons for this? I'm developing website in dotnetnuke.</p>
  
  <p>The JS I have written is syntactically and logically correct.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var displayTime, speed, wait, banner1, banner2, link1, link2, bannerIndex, bannerLocations, bannerURLs;
  
  function initVar() {
      debugger;
  
    displayTime = 10; // The amount of time each banner will be displayed in seconds.
    speed = 5; // The speed at which the banners is moved (1 - 10, anything above 5 is not recommended).
    wait = true;
  
    banner1 = document.getElementById("banner1");
    banner2 = document.getElementById("banner2");
    //link1 = document.getElementById("link1");
    //link2 = document.getElementById("link2");
  
    //banner1 = document.getElementById("banner1");
    //banner2 = document.getElementById("banner2");
  
    banner1.style.left = 0;
    banner2.style.left = 500;
  
    bannerIndex = 1;
  
    /* Important: In order for this script to work properly, please make sure that the banner graphic and the
    URL associated with it have the same index in both, the bannerLocations and bannerURLs arrays.
    Duplicate URLs are permitted. */
  
    // Enter the location of the banner graphics in the array below.
    //bannerLocations = new Array("internet-lg.gif","jupiterweb.gif","jupitermedia.gif");
  
    bannerLocations = new Array("image00.jpg", "image01.jpg", "image02.jpg", "admin_ban.bmp");
  
    // Enter the URL's to which the banners will link to in the array below.
    bannerURLs = new Array("http://www.internet.com","http://www.jupiterweb.com","http://www.jupitermedia.com");
  }
  
  function moveBanner() {
      //debugger;
    if(!wait){
      banner1.style.left = parseInt(banner1.style.left) -  (speed * 5);
      banner2.style.left = parseInt(banner2.style.left) - (speed * 5);
      if(parseInt(banner1.style.left) &lt;= -500){
        banner1.style.left = 500;
        bannerIndex = (bannerIndex &lt; (bannerLocations.length - 1)) ? ++bannerIndex :0;
        banner1.src = bannerLocations[bannerIndex];
        //link1.href = bannerURLs[bannerIndex];
        wait = true;
      }
      if(parseInt(banner2.style.left) &lt;= -500){
        banner2.style.left = 500;
        bannerIndex = (bannerIndex &lt; (bannerLocations.length - 1)) ? ++bannerIndex :0;
        banner2.src = bannerLocations[bannerIndex];
        //link2.href = bannerURLs[bannerIndex];
        wait = true;
      }
  
      setTimeout("moveBanner()",100);
    } else {
        wait = false;
        setTimeout("moveBanner()", displayTime * 1000);
    }
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>REGISTRATION IN JS</p>
  
  <pre><code>&lt;body onload="initVar(); moveBanner();"&gt;
  
  &lt;/body&gt;
  </code></pre>