title: how can i validate the date for my reservation?
body: <p>I made a reservation form, and I need a date validation. </p>
  
  <p>If the date is less than the current date, it should show an alert message saying "Please select a higher date" the stay on the page to change the date. But there is problem in my alert: when I choose a higher date, it still shows the alert message. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="tcal.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
  &lt;link href="bootstrap/css/bootstrap.css" rel="stylesheet"/&gt;
  &lt;script type="text/javascript" src="tcal.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  function showUser(str) {
    if (str=="") {
      document.getElementById("txtHint").innerHTML="";
      return;
    } 
    if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
  }
  
  &lt;/script&gt;
  
  &lt;script&gt;
    function showCottage(str) {
    if (str=="") {
      document.getElementById("txtcot").innerHTML="";
      return;
    } 
    if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
        document.getElementById("txtcot").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","getcottage.php?q="+str,true);
    xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  session_start();
  $message=''; //error message
  $reserve=@$_POST['reserve'];
  $dayCount = date("d");
  $year = date("Y");
  $month = date("m");
  $currentDate = $year.'-'.$month.'-'.$dayCount;
  
  if ($reserve &lt;= $currentDate){
    ?&gt; 
      &lt;script type="text/javascript"&gt;
      function myFunction(){
        alert("Please select a higher date!"); 
        return false;
        //history.back();
      }
      &lt;/script&gt; 
    &lt;?php 
    }
  
   ?&gt;
  
  
  
  &lt;form action="all.php" method="post" onsubmit="return myFunction()"&gt;
  
  &lt;div class="container"&gt;
  &lt;div id='fg_contact'&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Contact Details&lt;/legend&gt;
  
  &lt;input type="text" name="name" class="txt" placeholder="Full Name:" /&gt;&lt;br/&gt;
  &lt;input type="text" name="address" class="txt" placeholder="Address:" /&gt;&lt;br/&gt;
  &lt;input type="text" name="contact" class="txt" placeholder="Contact Number:" /&gt;&lt;br/&gt;
  &lt;input type="text" name="email" class="txt" placeholder="Email Address:" /&gt;&lt;br/&gt;
  &lt;/fieldset&gt;
  &lt;/div&gt;
  &lt;br/&gt;
  
  &lt;div id='fg_reservation'&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Reservation Details&lt;/legend&gt;
  
  &lt;p&gt;
          &lt;label for="password"&gt;Date&lt;/label&gt;&lt;br/&gt;
          &lt;input name="reserve" type="text" class="tcal txt-reg" id="fgh"/&gt;
  &lt;/p&gt;
  &lt;br/&gt;&lt;br/&gt;
  
  &lt;table class="table-res"&gt;
  &lt;td class="table-td"&gt;
  
  &lt;select class="txt-reg" name="users" onchange="showUser(this.value)"&gt;
  &lt;option &gt;Select a time:&lt;/option&gt;
  &lt;option value="1"&gt;DayTime&lt;/option&gt;
  &lt;option value="2"&gt;NightTime&lt;/option&gt;
  &lt;option value="3"&gt;OverNight&lt;/option&gt;
  &lt;/select&gt;
  &lt;br&gt;
  &lt;div id="txtHint"&gt;&lt;b&gt;Person info will be listed here.&lt;/b&gt;&lt;/div&gt;
  &lt;br/&gt;
  
  
  &lt;select class="txt-reg" name="Cot" onchange="showCottage(this.value)"&gt;
  &lt;option &gt;Select a cottage:&lt;/option&gt;
  &lt;option value="4"&gt;Cottage1&lt;/option&gt;
  &lt;option value="5"&gt;Cottage2&lt;/option&gt;
  &lt;option value="6"&gt;Cottage3&lt;/option&gt;
  &lt;option value="7"&gt;Cottage4&lt;/option&gt;
  &lt;option value="8"&gt;Cottage5&lt;/option&gt;
  &lt;option value="9"&gt;Cottage6&lt;/option&gt;
  
  &lt;option value="10"&gt;Cottage7&lt;/option&gt;
  &lt;option value="11"&gt;Cottage8&lt;/option&gt;
  &lt;option value="12"&gt;Cottage9&lt;/option&gt;
  &lt;option value="13"&gt;Cottage10&lt;/option&gt;
  &lt;option value="14"&gt;Cottage11&lt;/option&gt;
  &lt;option value="15"&gt;Cottage12&lt;/option&gt;
  
  &lt;option value="16"&gt;Cottage14&lt;/option&gt;
  &lt;option value="17"&gt;Cottage15&lt;/option&gt;
  &lt;option value="18"&gt;Cottage16&lt;/option&gt;
  &lt;option value="19"&gt;Cottage17&lt;/option&gt;
  &lt;option value="20"&gt;Cottage18&lt;/option&gt;
  &lt;option value="21"&gt;Cottage19&lt;/option&gt;
  
  &lt;option value="22"&gt;Cottage20&lt;/option&gt;
  &lt;option value="23"&gt;Cottage21&lt;/option&gt;
  &lt;option value="24"&gt;Cottage22&lt;/option&gt;
  &lt;option value="25"&gt;Cottage23&lt;/option&gt;
  &lt;option value="26"&gt;Cottage24&lt;/option&gt;
  &lt;option value="27"&gt;Cottage25&lt;/option&gt;
  
  &lt;option value="28"&gt;Cottage26&lt;/option&gt;
  &lt;option value="29"&gt;Cottage27&lt;/option&gt;
  &lt;option value="30"&gt;Cottage28&lt;/option&gt;
  &lt;option value="31"&gt;Cottage29&lt;/option&gt;
  &lt;option value="32"&gt;Cottage30&lt;/option&gt;
  &lt;option value="33"&gt;Cottage31&lt;/option&gt;
  
  &lt;option value="34"&gt;Cottage32&lt;/option&gt;
  &lt;option value="35"&gt;Cottage33&lt;/option&gt;
  &lt;option value="36"&gt;Cottage34&lt;/option&gt;
  &lt;option value="37"&gt;Cottage35&lt;/option&gt;
  &lt;option value="38"&gt;Cottage36&lt;/option&gt;
  &lt;option value="39"&gt;Cottage37&lt;/option&gt;
  
  &lt;option value="40"&gt;Cottage38&lt;/option&gt;
  &lt;option value="41"&gt;Cottage39&lt;/option&gt;
  &lt;option value="42"&gt;Cottage40&lt;/option&gt;
  &lt;option value="43"&gt;Cottage41&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;div id="txtcot"&gt;&lt;b&gt;Price of cottage will show here.&lt;/b&gt;&lt;/div&gt;
  &lt;br/&gt;&lt;/td&gt;
  
  &lt;td class="table-td"&gt;
  Adult's Head Count :&lt;br/&gt;
  &lt;input type="text" class="txt-reg" name="headcount1" value="0" /&gt;&lt;br/&gt;
  Children's Head Count :&lt;br/&gt;
  &lt;input type="text" class="txt-reg" name="headcount2" value="0" /&gt;&lt;br/&gt;&lt;br/&gt;
  
  &lt;input type="submit" value="Calculate Discount" /&gt;
  &lt;/td&gt;
  &lt;/table&gt;
  &lt;/fieldset&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>