Copy link to clipboard
Copied
Im working on a form where I need a date to auto populate every time the file is opened . I need it to populate the date 1 year ago.
I have used the following scripts to populate the "WED" and "UED" fields with the current date:
function dateToday() {
var d = new Date();
f = this.getField("WED");
f.value = d;
}dateToday();
So now im looking for a way to populate the "WSD" and "USD" form fields with a date 1 year prior to the current date.
Im new to this and self taught so please bear with me.
Copy link to clipboard
Copied
For example to populate "WSD" field with one year less then "WED" field, in "WED" field as validation script use this:
if(event.value == "")
this.getField("WSD").value = "";
else{
var days = util.scand("mm/dd/yyyy", event.value)
days.setFullYear(days.getFullYear() -1);
this.getField("WSD").value = util.printd("mm/dd/yyyy", days);}
Copy link to clipboard
Copied
For example to populate "WSD" field with one year less then "WED" field, in "WED" field as validation script use this:
if(event.value == "")
this.getField("WSD").value = "";
else{
var days = util.scand("mm/dd/yyyy", event.value)
days.setFullYear(days.getFullYear() -1);
this.getField("WSD").value = util.printd("mm/dd/yyyy", days);}
Copy link to clipboard
Copied
Thank you!!
Copy link to clipboard
Copied
Hi, I am attempting to learn JavaScript as I feel that I have a complex calculation involving dates. Please correct me if there is a way to do this without writing code.
In my PDF form, the employee will fill in a date that they need to begin using our gym facilities. For example they need to start using the gym on September 1, 2023. Since membership dues are paid one month in advance, I need the form to auto-populate the first day of the prior month. Therefore for the September 1 example, I need the payment date field to auto-populate with August 1, 2023.
Can you advise how I can achieve this?
Copy link to clipboard
Copied
Please post this question to a new thread, since it is a new question.
Copy link to clipboard
Copied
So here's script that will create a date 1 year from the current day
var today = new Date;
var oneYear = new Date((d.getMonth()+1).toString() +"/"+ d.getDate()+"/"+(d.getFullYear() + 1).toString());
this.getField("WED").value = oneYear;
And here is a simpler script for your current date .
this.getField("WED").value = new Date;
Copy link to clipboard
Copied
Why is this marked as correct answer?
It's not what OP asked for, he wants one year prior to current date and not one year after current date, and field name should be "WSD" because "WED" is already populated with current date, and what is the point of variable today?
Copy link to clipboard
Copied
Why is this marked as correct answer?
By @Asim123
You're correct in a way, however I'm not providing a custom solution. I'm pointing out how a script could be written to solve the issue. It's up to the user to fit it into thier project. I also don't see where it's marked as correct?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more