Amend some Javascript validation code for a date picker so tomorrows date is excluded
- or -
Post a project like this3341
£35(approx. $44)
- Posted:
- Proposals: 3
- Remote
- #223022
- Awarded
Description
Experience Level: Intermediate
I have a web form on a Joomla website using BreezingForms. It includes a date picker so visitors can choose a booking date.
I currently have some validation code on the form submission routine that alerts if the date is in the past, is a Sunday or is todays date, but I also need it to alert if the visitor selects tomorrows date.
Hopefully this is a quick and easy bit of coding for someone who knows Javascript, current code is below. I don't mind if this is adjusted or its completely re-written, whatever is easier so long as it alerts for past dates, today or tomorrow and Sundays.
function ff_date_validation(element, message)
{
var data = element.value ;
data = data.replace("/","-");
var dmy = data.split("-");
if (dmy.length != 3)
{
return ( message == '' ) ? message : " Please tell us which day you'd like the service to take place " ;
}
var vDate = new Date(dmy[2] - 0, dmy[1] -1, dmy[0] - 0,0,0,0,0);
//alert(vDate);
var today = new Date();
//alert(today);
if(vDate.getTime() 1)
{
return "Unfortunately we cannot take bookings for today or tomorrow.";
}
}
else
{
return "The date cannot be in the past.";
}
}
if ((vDate.getDay() == 0) || (vDate.getDay() == 7))
{
return "Unfortunately we cannot take bookings on Sundays";
}
return '';
} // ff_date_validation
I currently have some validation code on the form submission routine that alerts if the date is in the past, is a Sunday or is todays date, but I also need it to alert if the visitor selects tomorrows date.
Hopefully this is a quick and easy bit of coding for someone who knows Javascript, current code is below. I don't mind if this is adjusted or its completely re-written, whatever is easier so long as it alerts for past dates, today or tomorrow and Sundays.
function ff_date_validation(element, message)
{
var data = element.value ;
data = data.replace("/","-");
var dmy = data.split("-");
if (dmy.length != 3)
{
return ( message == '' ) ? message : " Please tell us which day you'd like the service to take place " ;
}
var vDate = new Date(dmy[2] - 0, dmy[1] -1, dmy[0] - 0,0,0,0,0);
//alert(vDate);
var today = new Date();
//alert(today);
if(vDate.getTime() 1)
{
return "Unfortunately we cannot take bookings for today or tomorrow.";
}
}
else
{
return "The date cannot be in the past.";
}
}
if ((vDate.getDay() == 0) || (vDate.getDay() == 7))
{
return "Unfortunately we cannot take bookings on Sundays";
}
return '';
} // ff_date_validation

Richard P.
100% (82)Projects Completed
82
Freelancers worked with
44
Projects awarded
66%
Last project
7 Feb 2022
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We use cookies to improve your experience and our services. By using PeoplePerHour, you agree to ourCookie Policy