title: Why is the Body Onload not work with function
body: <p>I don't why this is happening and it probably just a basic mistake but my <code>body</code> is able to call a function because:</p>
  
  <p><code>Uncaught ReferenceError: changeImg is not defined</code></p>
  
  <p>Here is my relevant PHP/HTML:</p>
  
  <p><code>&lt;?php print("&lt;body onLoad='javascript:changeImg(year_" . $p_date[0] . ")'&gt;"); ?&gt;</code></p>
  
  <p>And my JavaScript functions:</p>
  
  <pre><code>var currentImg = 0;
  var totalImg = 0;
  var stored_year = 0;
  
  $("#next-button").click(function() {
      if (currentImg == totalImg) {
          currentImg = 0;
      }
      else {
          currentImg++;
      }
      changeImg();
  });
  
  $("#previous-button").click(function() {
      if (currentImg == 0) {
          currentImg = totalImg;
      }
      else {
          currentImg--;
      }
      changeImg();
  });
  
  function changeImg(galleryYear) {
  
      if (galleryYear = stored_year) {
  
  
          $("#gallery-image").html("&lt;img src='" + galleryYear.x_src[currentImg] + "'&gt;");
          $("#gallery-title").html(galleryYear.x_title[currentImg]);
          $("#gallery-medium").html(galleryYear.x_medium[currentImg]);
          $("#gallery-size").html(galleryYear.x_size[currentImg]);
          $("#gallery-date").html(galleryYear.x_date[currentImg]);
  
          var userCurrent = currentImg + 1;
          var userTotal = galleryYear.x_id.length;
  
          $("#current-post").html(userCurrent);
          $("#post-total").html(userTotal);
  
          var galWidth = $("#gallery-image" &gt; "img").width();
          $("#gallery").width(galWidth);
  
      }
      else {
  
          currentImg = 0;
          $("#gallery-image").html("&lt;img src='" + galleryYear.x_src[currentImg] + "'&gt;");
          $("#gallery-title").html(galleryYear.x_title[currentImg]);
          $("#gallery-medium").html(galleryYear.x_medium[currentImg]);
          $("#gallery-size").html(galleryYear.x_size[currentImg]);
          $("#gallery-date").html(galleryYear.x_date[currentImg]);
  
          var userCurrent = currentImg + 1;
          var userTotal = galleryYear.x_id.length;
  
          $("#current-post").html(userCurrent);
          $("#post-total").html(userTotal);
  
          var galWidth = $("#gallery-image" &gt; "img").width();
          $("#gallery").width(galWidth);
  
          $("#gallery-type").html('&lt;img id="gallery-switch" alt="" src="images/gallery-icon.png" onClick="gallerySwitch()"&gt;');
  
          stored_year = galleryYear;
      }
  
  }
  </code></pre>
  
  <p>It was working earlier but why not now?</p>