Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Date/Time Check - Must be 60 minutes after current time

    I have a restaurant order system built in Classic ASP. On the order menu there are fields for order pickup time and date:

    Code:
    <form>
    <input type="text" size="12" name="pickupDate" id="datepicker">
    <select name="orderTime" id="orderTime" class="validate[required]"></select>
    </form>
    My client wants validation added to make sure the order pickup date and time is a minimum of 60 minutes from the current time. How can I add this in JavaScript so an error message shows in red below these fields if the customer selects a date/time that is under 60 minutes from the current date and time?

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    var rightNow = new Date();
    var month = rightNow.getMonth();
    var dayt = rightNow.getDate();
    var year = rightNow.getFullYear();
    var hours = rightNow.getHours();
    var minutes = rightNow.getMinutes();
    var seconds= rightNow.getSeconds();
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your reply on this, but I don't see any coding where the current date/time is checked against what is entered in the form fields.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <script type="text/javascript">
    
    // add 60 minutes to current time
    
    var theTime = new Date();
    theTime.setTime(theTime.getTime() + 60 * 60 * 1000);
    alert (theTime);
    	
    </script>
    So any requested delivery before that date/time is invalid.

    But the problem with this is that the time is taken from the user's browser. So I can change the "time" by altering my computer clock.

    You will need to use server-side coding (ASP) to ensure that the requested delivery time is at least 60 minutes after the current time.

    Quizmaster: In nature, what invertebrate has a name which literally means "one hundred feet"?
    Contestant: Giraffe

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •