title: Uncaught ReferenceError: functionName is not defined
body: <p>I have checked out this <a href="https://stackoverflow.com/questions/7612218/how-can-i-call-a-javascript-function-when-checkbox-is-checked">thread</a> and <a href="https://stackoverflow.com/questions/5067887/uncaught-referenceerror-function-is-not-defined-in-document-readyfunction">this one</a> but it didn't really help me.</p>
  
  <p>I have a ASP:CheckBox control shown below.</p>
  
  <pre><code>&lt;asp:CheckBox ID="chbArchived" runat="server" Checked='&lt;%# Bind("archived") %&gt;' OnClick=changeExpirationDate() /&gt;
  </code></pre>
  
  <p>My JavaScript are follows:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              //alert("got here");
              $('.insDateTime').datetimepicker({
                  ampm: true
              });
              changeExpirationDate(){
                  var currentDate = new Date;
                  var futureDateTime = (currentDate.getMonth() + 4) + '/' + currentDate.getDate() + '/' + currentDate.getFullYear() + ' ' + formatAMPM(currentDate);
                  var expiredDateTime = (currentDate.getMonth() + 1) + '/' + currentDate.getDate() + '/' + currentDate.getFullYear() + ' ' + formatAMPM(currentDate);
                  var archivedCheckbox = document.getElementById('cphContent_fmvNewsEventList_chbArchived').checked;
                  if(archivedCheckbox == true)
                  {
                      document.getElementById('cphContent_fmvNewsEventList_txtExpirationDate').value = expiredDateTime;
                  }
                  else{
                      document.getElementById('cphContent_fmvNewsEventList_txtExpirationDate').value = futureDateTime;
                  }
              };
              function formatAMPM(date) {
                  var hours = date.getHours();
                  var minutes = date.getMinutes();
                  var ampm = hours &gt;= 12 ? 'pm' : 'am';
                  hours = hours % 12;
                  hours = hours ? hours : 12; // the hour '0' should be '12'
                  minutes = minutes &lt; 10 ? '0'+minutes : minutes;
                  var strTime = hours + ':' + minutes + ' ' + ampm;
                  return strTime;
              };
          });        
      &lt;/script&gt;
  </code></pre>
  
  <p>The problem is I kept getting this JavaScript error "Uncaught ReferenceError: changeExpirationDate is not defined" when I clicked on the checkbox. Any suggestion/help is much appreciated.</p>