title: Javascript functions not being called in JSPs
body: <p>SOLVED: Stray <code>}</code> within the Javascript. Eclipse IDE doesn't check these when in a JSP.</p>
  
  <p>I'm having trouble getting my Javascript functions to be called in my JSP. I have commented above which functions are working and not working. My goal is to have my dropdown boxes to be preselected based on a passed parameter.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      //this alert not working
      alert('alert1');
  
  function preloadDropdownBoxes() {
      //preload function alert not calling
      alert('preload function called');
      //mapping vars to java variables
      var sYear = '&lt;%=sYear%&gt;';
      var collectionPeriod = '&lt;%=collectionPeriod%&gt;';
      var submission = '&lt;%=submission%&gt;';
      var availDate = '&lt;%=availDate%&gt;';
      var openDate = '&lt;%=openDate%&gt;';
      var closeDate = '&lt;%=closeDate%&gt;';
      //these are time generated values based on calendar instance
      var pastTwoYear = '&lt;%=pastTwoYear%&gt;';
      var pastYear = '&lt;%=pastYear%&gt;';
      var currentYear = '&lt;%=currentYear%&gt;';
      var futureYear = '&lt;%=futureYear%&gt;';
      //change selectedIndex values if dropdown in JSP has "pastTwoYear"
      if (sYear == pastTwoYear) {
          document.getElementById('pastTwoYear').selectedIndex = 0;
      } else if (sYear == pastYear) {
          document.getElementById('past').selectedIndex = 0;
          alert(sYear + '0');
      } else if (sYear == currentYear) {
          document.getElementById('current').selectedIndex = 1;
          alert(sYear + '1');
      } else if (sYear == futureYear) {
          document.getElementById('future').selectedIndex = 2;
          alert(sYear + '2');
      } else if(sYear == futureTwoYear) {
          document.getElementById('futureTwoYear').selectedIndex = 3;
          alert(sYear + '3');
      }
  } //end preLoadDropdownBoxes()
  &lt;/script&gt;
  </code></pre>
  
  <p>I then have code for my dropdown boxes. Here is a snippet:</p>
  
  <pre><code>&lt;select name="sYear1" id="sYear1" onchange="javascript:PreselectMyItem();"&gt;
                          &lt;option value="past"&gt;&lt;%=cal.get(java.util.Calendar.YEAR)-2%&gt;-&lt;%=cal.get(java.util.Calendar.YEAR)-1%&gt;&lt;/option&gt;
                          &lt;option value="current"&gt;&lt;%=cal.get(java.util.Calendar.YEAR)-1%&gt;-&lt;%=cal.get(java.util.Calendar.YEAR)%&gt;&lt;/option&gt;
                          &lt;option value="future"&gt;&lt;%=cal.get(java.util.Calendar.YEAR)%&gt;-&lt;%=cal.get(java.util.Calendar.YEAR)+1%&gt;&lt;/option&gt;
                      &lt;/select&gt;
  </code></pre>
  
  <p>Now, finally, I have another script on the bottom. I plan on putting my <code>preloadDropdownBoxes();</code> function at the end. I tried used <code>$(document).ready</code> but it wasn't working. Code is as follows:</p>
  
  <pre><code>    &lt;script&gt;
  //     these two alert calls work
  alert('footer');
  alert('footer next');
  //     these functions aren't being called
  window.preloadDropdownBoxes();
  document.getElementById('future').selectedIndex = 2;
  window.alert('document ready on bottom');
  
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Edit: I've made my Test button as follows <code>&lt;input type="button" value="test" onclick="javascript:alert('test');"/&gt;</code> and this alert does work. There seems to be something wrong with the document not being able to register the functions in my script up top because I tried
          function test() {
          alert('hello');
      }
  But the above snippet function isn't called when the button is: <code>&lt;input type="button" value="test" onclick="javascript:test();"/&gt;</code>  </p>