title: JavaScript Giving 'Object Expected' Error
body: <p>I am writing some code that shows or hides a calendar based on a drop down select form. I have it set to run my showHideCalendar() function as an onchange action on the drop down selection. When I change the selected option I receive an "Object expected" error. I have included the relevant HTML and JavaScript code.</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
  function showHideCalendar(element) {
      document.getElementById("calendar").style.display = "none";        
      if (document.getElementById("dropdown").selectedIndex === 13) {
          cal5.popup();
          document.getElementById("textField").value = "";
          document.getElementById("calendar").style.display = "inline";        
      }
  }
  
  &lt;/script&gt;
  
  &lt;FORM NAME='Labs' METHOD='POST' ACTION=""&gt;
  &lt;select id="dropdown" name='TimeFrame0' onchange='showHideCalendar(document.Labs.TimeFrame0)'&gt;
      &lt;option value='NoReorder'&gt;Do Not Reorder&lt;/option&gt;
      &lt;option value='2012-06-14 08:40:39.067'&gt;Today&lt;/option&gt;
      &lt;option value='2012-06-21 08:40:39.067'&gt;1 Week&lt;/option&gt;
      &lt;option value='2012-06-28 08:40:39.067'&gt;2 Weeks&lt;/option&gt;
      &lt;option value='2012-07-05 08:40:39.067'&gt;3 Weeks&lt;/option&gt;
      &lt;option value='2012-07-12 08:40:39.067'&gt;4 Weeks&lt;/option&gt;
      &lt;option value='2012-07-26 08:40:39.067'&gt;6 Weeks&lt;/option&gt;
      &lt;option value='2012-07-14 08:40:39.067' selected&gt;1 Month&lt;/option&gt;
      &lt;option value='2012-08-14 08:40:39.067'&gt;2 Months&lt;/option&gt;
      &lt;option value='2012-09-14 08:40:39.067'&gt;3 Months&lt;/option&gt;
      &lt;option value='2012-10-14 08:40:39.067'&gt;4 Months&lt;/option&gt;
      &lt;option value='2012-12-14 08:40:39.067'&gt;6 Months&lt;/option&gt;
      &lt;option value='2013-03-14 08:40:39.067'&gt;9 Months&lt;/option&gt;
      &lt;option value='custom' id='custom'&gt;Calendar Select&lt;/option&gt;
  &lt;/select&gt;                    
  
  &lt;div id='calendar' style='display:inline'&gt;
      &lt;input type=text name='StartDate' value='' size=20 onchange='inputChanged()' onkeydown='inputChanged()' onblur='inputChanged()' id='textField'&gt;
      &lt;a href='javascript:cal5.popup();' onmousedown='inputChanged()'&gt; &lt;img src='/jscalendar/img/cal.gif' width='16' height='16' border='0' alt='Click Here to Pick up the date'&gt;&lt;/a&gt;
  &lt;/div&gt;
  &lt;input type=checkbox name=SameDate value='on' checked onClick='SetTimeFrame(document.Labs.TimeFrame0)'&gt; Use Same Date For All Labs
  &lt;input class='btnsave' type=button name=Save value='Reorder Labs' onClick=javascript:document.Labs.action='/LabReview/Reorder.php?PROV=PROVID&amp;MaxCount=2&amp;Text=1';document.Labs.submit();&gt;
  &lt;input class='btncancel' type=button name=Cancel value=Cancel onClick=javascript:top.window.close()&gt;      
  &lt;/FORM&gt;
  </code></pre>
  
  <p>Does anyone see any reason why this is not working. The error is thrown on the line <code>&lt;select id="dropdown" name='TimeFrame0' onchange='showHideCalendar(document.Labs.TimeFrame0)'&gt;</code>.</p>
  
  <p>One of the answerers thinks the error isn't in my new code, but rather something else on the page. I am editing my question to add the rest of the javascript that is on the page.</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
  
      function showHideCalendar(element) {
          document.getElementById("calendar").style.display = "none";        
          if (document.getElementById("dropdown").selectedIndex === 13) {
              cal5.popup();
              document.getElementById("textField").value = "";
              document.getElementById("calendar").style.display = "inline";        
          }
      }
  
      function inputChanged() {
          document.getElementById("dropdown").selectedIndex = 13;
      }
  
     function SetTimeFrame(element)
       {       
         if (document.Labs.SameDate.checked==true)
           {
             var Elements=document.Labs.elements.length;
           for (var i=0; i&lt;Elements; i++)
             {
            if (document.Labs.elements[i].type=='select-one')
                {                      
                     document.Labs.elements[i].options[element.selectedIndex].selected=true;
                }        
           }    
           }
       }
  
     if (top.window.opener.document.getElementById("Complete&lt;?php echo($_GET['Item']); ?&gt;"))
       {
         if ('&lt;?php echo($Reviewed); ?&gt;' == 'yes')
            {
                  window.opener.document.getElementById("Complete&lt;?php echo($_GET['Item']); ?&gt;").style.visibility='visible';       
                   window.opener.document.getElementById("Partial&lt;?php echo($_GET['Item']); ?&gt;").style.visibility='hidden';       
          }
            else if ('&lt;?php echo($Reviewed); ?&gt;' == 'partial')
           {
                     window.opener.document.getElementById("Partial&lt;?php echo($_GET['Item']); ?&gt;").style.visibility='visible';       
                      window.opener.document.getElementById("Complete&lt;?php echo($_GET['Item']); ?&gt;").style.visibility='hidden';       
          }
     }    
       else
       {
                var temp=top.window.opener.location.href;
               top.window.opener.location.href=temp;    
               top.window.opener.top.window.location.reload(); 
       }
  
  function DateCheck(element)
  {
    var xx = element.value;
    var re = new RegExp("^[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]$");
    var re2 = new RegExp("^[0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]$");
      var re3 = new RegExp("^[0-9][0-9]/[0-9]/[0-9][0-9][0-9][0-9]$");
      var re4 = new RegExp("^[0-9]/[0-9]/[0-9][0-9][0-9][0-9]$");
  
      var error = "";
    var maxdays = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
    var retval = true;
    if(element.value != "")
    {
      if(xx.search(re) &lt; 0 &amp;&amp; xx.search(re2) &lt; 0 &amp;&amp; xx.search(re3) &lt; 0 &amp;&amp; xx.search(re4) &lt; 0)
      {
      error = "Invalid Date Format " + xx + ". Please enter dates in the format mm/dd/yyyy."
      retval = false;
      element.value = ""
      }
      else
      {
      var list = xx.split("/");
      var month = list[0];
      if(month.charAt(0) == "0")
      month = month.substr(1);
      if( list[0] &lt; 1 || list[0] &gt; 12)
      {
          error = "Invalid Month " + list[0];
          retval = false;
          element.value = ""
      }
      else 
      if(list[1] &lt; 1 || list[1] &gt; maxdays[month])
      {
          error = "Invalid Day " + list[1];
          retval = false;
          element.value = ""
      }
      else 
      if(list[2] &lt; 1900)
      {
          error = "Invalid Year (Must be greater than 1900) " + list[2];
          retval = false;    
          element.value = ""
      }
      }
      if(!retval)
      alert(error);
  
      return retval;
    }
  }
  
  
  
  &lt;/script&gt;
  </code></pre>