title: Validating a Date
body: <p>I have an assignment for javascript class that requires me to validate a date. The teacher provided a function for the actual validation, but the rest is up to me.  I've been working on this for a couple hours and I'm stuck. Here's what I have so far...</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Date Validation&lt;/title&gt;
  &lt;script type="text/javascript"&gt; 
  
  var month = document.validateDate.month.value;
  var day = document.validateDate.day.value;
  var year = document.validateDate.year.value;
  
  
  
  function validDate( month, day, year) 
  { 
     // Test for leap year 
      if ((year % 400 == 0) || (year % 4 == 0) &amp;&amp;                 
         !(year % 100 == 0)) 
            leap = true; 
      else 
            leap = false; 
  
      // Validate date                              // Assume a valid date-test otherwise
      if (year &lt; 1900 || year &gt; 2050)               // year must be four digits and      
          return false;                             //     within reasonable range 
      else if ((month &lt; 1) || (month &gt; 12) ||       // test general date and month range 
               (day &lt; 1) || (day &gt; 31)) 
          return false;      
      else if (((month == 4) || (month == 6) ||     // test 30 Day months 
                (month == 9) || (month == 11)) &amp;&amp; (day == 31)) 
          return false;      
      else if (month == 2 &amp;&amp; leap &amp;&amp; day &gt; 29)      // test February leap years 
          return false;          
      else if (month == 2 &amp;&amp;  !leap &amp;&amp; day &gt; 28)    // test February NON-leap years 
          return false;          
      else 
          return true;                              // otherwise, date is OK 
  
  } 
  &lt;/script&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Date Validator&lt;/h1&gt;
  
  &lt;p&gt;Please enter a date to be validated, then press "Validate"&lt;/p&gt;
  &lt;form action="" name="validateDate"&gt;
  &lt;select name="month"&gt;
  &lt;option value="1"&gt;January
  &lt;option value="2"&gt;February
  &lt;option value="3"&gt;March
  &lt;option value="4"&gt;April
  &lt;option value="5"&gt;May
  &lt;option value="6"&gt;June
  &lt;option value="7"&gt;July
  &lt;option value="8"&gt;August
  &lt;option value="9"&gt;September
  &lt;option value="10"&gt;October
  &lt;option value="11"&gt;November
  &lt;option value="12"&gt;December
  &lt;/select&gt;
  
  &lt;select name="day"&gt;
  &lt;option value="1"&gt;1
  &lt;option value="2"&gt;2
  &lt;option value="3"&gt;3
  &lt;option value="4"&gt;4
  &lt;option value="5"&gt;5
  &lt;option value="6"&gt;6
  &lt;option value="7"&gt;7
  &lt;option value="8"&gt;8
  &lt;option value="9"&gt;9
  &lt;option value="10"&gt;10
  &lt;option value="11"&gt;11
  &lt;option value="12"&gt;12
  &lt;option value="13"&gt;13
  &lt;option value="14"&gt;14
  &lt;option value="15"&gt;15
  &lt;option value="16"&gt;16
  &lt;option value="17"&gt;17
  &lt;option value="18"&gt;18
  &lt;option value="19"&gt;19
  &lt;option value="20"&gt;20
  &lt;option value="21"&gt;21
  &lt;option value="22"&gt;22
  &lt;option value="23"&gt;23
  &lt;option value="24"&gt;24
  &lt;option value="25"&gt;25
  &lt;option value="26"&gt;26
  &lt;option value="27"&gt;27
  &lt;option value="28"&gt;28
  &lt;option value="29"&gt;29
  &lt;option value="30"&gt;30
  &lt;option value="31"&gt;31
  &lt;/select&gt;
  
  &lt;select name="year"&gt;
  &lt;option value="2011"&gt;2011
  &lt;option value="2012"&gt;2012
  &lt;option value="2013"&gt;2013
  &lt;option value="2014"&gt;2014
  &lt;option value="2015"&gt;2015
  &lt;option value="2016"&gt;2016
  &lt;option value="2017"&gt;2017
  &lt;option value="2018"&gt;2018
  &lt;option value="2019"&gt;2019
  &lt;option value="2020"&gt;2020
  &lt;/select&gt;
  
  &lt;input type="button" value="Validate" onclick="validDAte( month, day, year)"/&gt;
  &lt;br /&gt;
  
  &lt;input type="text" name="textbox" style="width:275"/&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The actual function was what was provided. The variables "month", "day", and "year" I put there. I can get the values, but I can't get them to work in the function. </p>
  
  <p>The net result is for the text box  at the bottom to say something like "1/1/2011 is a valid date." or "2/31/2011" is not a valid date." Please help...</p>