Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2013, 05:49 PM   PM User | #1
SteveSensei
New Coder

 
Join Date: Feb 2006
Posts: 62
Thanks: 1
Thanked 0 Times in 0 Posts
SteveSensei is an unknown quantity at this point
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?
SteveSensei is offline   Reply With Quote
Old 02-13-2013, 05:55 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 02-13-2013, 06:07 PM   PM User | #3
SteveSensei
New Coder

 
Join Date: Feb 2006
Posts: 62
Thanks: 1
Thanked 0 Times in 0 Posts
SteveSensei is an unknown quantity at this point
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.
SteveSensei is offline   Reply With Quote
Old 02-13-2013, 06:37 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02 AM.


Advertisement
Log in to turn off these ads.