Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date and time validation

Status
Not open for further replies.

Papapax

Programmer
Jun 10, 2008
1
Hi,

I have a problem with a date and time validation issue.

On I have a form to request a restaurant booking.

The validation on the time field should see if the the user is requesting a booking for the same day, if it is for the same day and the time for the booking is past 20:00 on the same day a javascript alert should notify the user to call the venue as the request is too close to the closing time.

Hopefully it makes sense, any help would be appreciated.

Thanks
Frank
 
If 20:00 is "too close to the closing time" why does it matter that it's on the same day?

_________________
Bob Rashkin
 
Bob,

Presumably because 8pm on the following day wouldn't be too close to closing time on the day the booking was made (it'd be at least 24 hours away - plenty of time for admin, etc).

Frank,

You should be able to get the hour by splitting the value of the select element on the colon. Pretend the variable 'bookingTime' holds the string '21:00' from your form :

Code:
var bookingTime = '21:00';
var hourPortion = parseInt(bookingTime.split(':')[0], 10);
if (hourPortion >= 20) {
   // fail validation here
}

Hope this helps,
Dan


Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top