title: Javascript Leap year date validation
body: <p>I tried searching for the solution in existing stackoverflow answers but I was not finding a suitable answer...</p>
  
  <p>I have 3fields..</p>
  
  <ul>
  <li>Year <code>select</code></li>
  <li>Month <code>select</code></li>
  <li>Date <code>select</code></li>
  </ul>
  
  <p>If you select the leap year means, February month date will change to 29 days.. But that still shows the 28 days.. Don't know what problem in my code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var numDays = {
          '1': 31, '2': 28, '3': 31, '4': 30, '5': 31, '6': 30,
          '7': 31, '8': 31, '9': 30, '10': 31, '11': 30, '12': 31
      };
  
      function setDays(oMonthSel, oDaysSel, oYearSel)
      {
          var nDays, oDaysSelLgth, opt, i = 1;
          nDays = numDays[oMonthSel[oMonthSel.selectedIndex].value];
          if (nDays == 28 &amp;&amp; oYearSel[oYearSel.selectedIndex].value % 4 == 0)
              ++nDays;
          oDaysSelLgth = oDaysSel.length;
          if (nDays != oDaysSelLgth)
          {
              if (nDays &lt; oDaysSelLgth)
                  oDaysSel.length = nDays;
              else
                  for (i; i &lt; nDays - oDaysSelLgth + 1; i++)
                  {
                      opt = new Option(oDaysSelLgth + i, oDaysSelLgth + i);
                      oDaysSel.options[oDaysSel.length] = opt;
                  }
          }
          var oForm = oMonthSel.form;
          var month = oMonthSel.options[oMonthSel.selectedIndex].value;
          var day = oDaysSel.options[oDaysSel.selectedIndex].value;
          var year = oYearSel.options[oYearSel.selectedIndex].value;
          oForm.dob.value = month + '/' + day + '/' + year;
      }
      var min = new Date().getFullYear(),
              max = min - 13,
              select = document.getElementById('year');
      for (var i = (min - 100); i &lt;= max; i++) {
          var opt = document.createElement('option');
          opt.value = i;
          opt.innerHTML = i;
          select.appendChild(opt);
      }
      date = document.getElementById('day');
      for (var i = 1; i &lt;= 31; i++) {
          var opt = document.createElement('option');
          opt.value = i;
          opt.innerHTML = i;
          date.appendChild(opt);
      }
      jQuery('.month_sel,.day_sel,.year_sel').selectpicker({
          size: 8
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;select class="year_sel common_sel" name="year" id="year" onchange="setDays(month, day, this)"&gt;
  &lt;option value=""&gt;Year&lt;/option&gt;
  &lt;/select&gt;
  &lt;select name="month" id="month" onchange="setDays(this, day,year)" class="month_sel common_sel"&gt;
  &lt;option value=""&gt;Month&lt;/option&gt;
  &lt;option value="1"&gt;January&lt;/option&gt;
  &lt;option value="2"&gt;February&lt;/option&gt;
  &lt;option value="3"&gt;March&lt;/option&gt;
  &lt;option value="4"&gt;April&lt;/option&gt;
  &lt;option value="5"&gt;May&lt;/option&gt;
  &lt;option value="6"&gt;June&lt;/option&gt;
  &lt;option value="7"&gt;July&lt;/option&gt;
  &lt;option value="8"&gt;August&lt;/option&gt;
  &lt;option value="9"&gt;September&lt;/option&gt;
  &lt;option value="10"&gt;October&lt;/option&gt;
  &lt;option value="11"&gt;November&lt;/option&gt;
  &lt;option value="12"&gt;December&lt;/option&gt;
  &lt;/select&gt;
  &lt;select class="day_sel common_sel" name="day" id="day" onchange="setDays(month, this, year)"&gt;
  &lt;option value=""&gt;Day&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="hidden" name="dob" value="" /&gt;</code></pre>
  </div>
  </div>
  </p>