Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, add numbers as values for months:</p> <pre><code>&lt;select name="mo"&gt; &lt;option disabled="disabled"&gt;SELECT 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; </code></pre> <p>Then use <a href="http://php.net/manual/en/function.checkdate.php" rel="nofollow">checkdate()</a>:</p> <pre><code>&lt;?php $month = $_POST["mo"]; $day = $_POST["theDay"]; $yr = $_POST["year"]; if (checkdate($month, $day, $yr) !== true) { // ? } ?&gt; </code></pre> <p>And if you want to do it in the browser as well, first add an onsubmit handler to the year form:</p> <pre><code>&lt;FORM method="POST" action="&lt;?php echo $PHP_SELF;?&gt;" onsubmit="return checkLeap(this);"&gt; </code></pre> <p>Then your function:</p> <pre><code>function checkLeap(form) { var month = form.mo.options[form.mo.selectedIndex].value; var day = form.theDay.options[form.theDay.selectedIndex].value; var year = form.year.options[form.year.selectedIndex].value; if (month == 2 &amp;&amp; day == 29 &amp;&amp; (new Date(year,month,year).getDate() != 29)) { alert('That is not a leap year. Please fix.'); return false; } return true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload