title: Object required error in javascript even when calling the function correctly
body: <p>Unhandled exception at line 289, column 13 in localhost:3659/advancesearch.aspx</p>
  
  <p>0x800a01a8 - Microsoft JScript runtime error: Object required</p>
  
  <p>I am calling the correct function but the error persists.</p>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      function CompareDate() {
          debugger;
          var fromDate = document.getElementById("fromtxtbox").value; (line 289)
          var toDate = document.getElementById("totextbox").value;
          var endDate = new Date(toDate);
          var startDate = new Date(fromDate);
  
          if (fromDate != '' &amp;&amp; toDate != '' &amp;&amp; startDate &gt; endDate) {
              alert('end date should be greater than or equal to start date');
              document.getElementById('totextbox').value = "";
              return false;
          }
          else if (fromDate == '') {
              alert('Please enter start date!');
              document.getElementById('fromtxtbox').focus();
              return false;
          }
          else if (toDate == '') {
              alert('Please enter end date!');
              return false;
          }
          else if (fromDate == '' &amp;&amp; endDate != '') {
              alert('please select from date!');
              return false;
          }
      }
  
  &lt;/script&gt;
  
  &lt;asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"&gt;
      &lt;asp:View ID="view1" runat="server"&gt;
  
  
          &lt;table align="left" cellspacing="5" width="590"&gt;
              &lt;tr&gt;
                  &lt;td colspan="3" style="background-color: #D3D8DE;"&gt;
                      &lt;table cellpadding="0" cellspacing="0"
                          style="border-top: 1px solid rgb(51, 102, 204);" width="100%"&gt;
                          &lt;tr&gt;
                              &lt;td style="height: 9px"&gt;&amp;nbsp;Advanced Search&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr id="sc" runat="server"&gt;
                  &lt;td align="right"&gt;Select Classified&lt;/td&gt;
                  &lt;td&gt;:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:RadioButton ID="radiobtnclass" runat="server" Text="class" GroupName="q"
                          AutoPostBack="True" Checked="True" ValidationGroup="1" /&gt;
                      &lt;asp:RadioButton ID="radiobtnDemo" runat="server" GroupName="q" Text="demo"
                          AutoPostBack="True" ValidationGroup="1" /&gt;
                      &amp;nbsp;&lt;asp:Label ID="Label1" runat="server" Text="Select Demo/Class"
                          Visible="False" ForeColor="#FF3300"&gt;&lt;/asp:Label&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Category &lt;/td&gt;
                  &lt;td&gt;:&lt;/td&gt;
                  &lt;td&gt;
  
                      &lt;asp:DropDownList ID="ddcategory" runat="server" Width="120px" Height="20px"
                          AutoPostBack="True" OnSelectedIndexChanged="ddcategory_SelectedIndexChanged1"&gt;
                          &lt;asp:ListItem Value="--select All--"&gt;--select All--&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Value="Software Training"&gt;Software Training&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Value="Call Center/BPO"&gt;Call Center/BPO&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Value="Non-IT Training"&gt;Non-IT Training&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Value="Medical Transcription"&gt;Medical Transcription&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Value="Spoken English"&gt;Spoken English&lt;/asp:ListItem&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Course Name&lt;/td&gt;
                  &lt;td&gt;:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="ddcoursename" runat="server" Width="120px" Height="20px"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;City&lt;/td&gt;
                  &lt;td&gt;:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="ddcity" runat="server" Width="120px"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Date&lt;/td&gt;
                  &lt;td&gt;:&lt;/td&gt;
                  &lt;td&gt;From&amp;nbsp;&amp;nbsp;
                      &lt;asp:TextBox ID="fromtxtbox" runat="server"&gt;&lt;/asp:TextBox&gt;
                      &lt;cc1:CalendarExtender ID="fromtxtbox_CalendarExtender" runat="server"
                          Enabled="True" TargetControlID="fromtxtbox" PopupPosition="TopLeft"&gt;
                      &lt;/cc1:CalendarExtender&gt;
                      To&lt;asp:CompareValidator ID="tocomparevalidator" runat="server"
                          ControlToCompare="totextbox" ControlToValidate="fromtxtbox" Display="Dynamic"
                          ErrorMessage="Selected date should be greater than or equal to From date"
                          Operator="LessThanEqual" Type="Date"
                          OnDataBinding="Page_Load" ValidationGroup="a"&gt;&lt;/asp:CompareValidator&gt;
                      &lt;asp:TextBox ID="totextbox" runat="server"&gt;&lt;/asp:TextBox&gt;
                      &lt;cc1:CalendarExtender ID="totextbox_CalendarExtender" runat="server" Enabled="True"
                              TargetControlID="totextbox" PopupPosition="TopRight"&gt;
                      &lt;/cc1:CalendarExtender&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                  &lt;td colspan="3" align="center" style="height: 35px"&gt;&amp;nbsp;
          &lt;br /&gt;
                      &lt;asp:Button ID="advancesearch_btn" runat="server" Text="search"
                          OnClick="Button1_Click" OnClientClick="javascript:return CompareDate();" ValidationGroup="a" /&gt;
                      &lt;asp:Label ID="Label22" runat="server" Text="Label" Visible="False"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="Label21" runat="server" Text="Label" Visible="False"&gt;&lt;/asp:Label&gt;
  </code></pre>