Copy link to clipboard
Copied
Hi Guys
I'm currently using Adobe Acrobat X Pro. I'm trying to create a form so that when the user inserts a date into a field a JavaScript will identify if this is a weekday or weekend. Depending on which is entered it will then add a specific rate. i.e. Weekday = £65 and Weekend =£130.
Can someone please help me or point me in the right direction?
Thanks
Copy link to clipboard
Copied
The getDay() method returns the day of the week (from 0 to 6) for the specified date.
Note: Sunday is 0, Monday is 1, and so on.
Copy link to clipboard
Copied
Hi
++ Adding to suggestion what you are looking for in your script is found in this Thom Parker's tutorial:Working with date and time in Acrobat JavaScript
https://acrobatusers.com/tutorials/date_time_part2
Use the included PDF practice file for your script which does just what you're looking for:
Copy link to clipboard
Copied
I forgot to add, however, that you should start with Part 1 of the turorial found here:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
Copy link to clipboard
Copied
Thank you for your advice and video links.
I'm still having difficulty finding a script that will know if the date selected is a weekday or weekend and auto populate another field with a specific rate i.e. £65 Weekday, £130 Weekend.
Copy link to clipboard
Copied
Bernd provided the correct answer, but the first thing the script needs to do is to convert the text date entry into a Date Object. How this is done depends on the format. But lets just assume for this example that it's simple.
This script was designed to go into the Custom validate script of the date field.
var oMyDate = util.scand("mm/dd/yyyy", event.value);
if(oMyDate)
{
var nDayOfWeek = oMyDate.getDay();
if((nDayOfWeek == 0) || (nDayOfWeek == 6))
this.getField("Rate").value = 130;
else
this.getField("Rate").value = 65;
}
else
this.getField("Rate").value = 0;