Skip to content Skip to sidebar Skip to footer

Warning Message/pop Out For Date/time

I have a form where a user need to enter date and time (2 different fields) and the time cannot be more than 12 hours old. So I want to add a warning message (most likely a pop-up

Solution 1:

<script language="JavaScript">
  function validate()
  {
    var dateEntered = new Date( document.getElementById("Date") + " " + document.getElementById("Time") );
    var dateNow = new Date();

    if( dateNow - dateEntered > 1000*60*60*12 )
    {
      alert( "Date entered is too old." );
      return( false );
    }
    return( true );
  }
</script>

<form method=post action="blah.html" onsubmit="JavaScript: return( validate() );">
  <input type=text id=Date name=Date>
  <input type=text id=Time name=Time>
  <input type=submit value="Submit">
</form>

Post a Comment for "Warning Message/pop Out For Date/time"