Using date to determine value in a field

New Here ,
Dec 06, 2020 Dec 06, 2020

Copy link to clipboard

Copied

Hi,

I am wanting to create a script to select a particular value, based on date.

Specifically, the selection will be based on the date occuring on or prior to 01/01/1996.  The date field is "DOB"  The field I want to autofill is named "CourseFee". 

 

I have two calculated fields and want to be able to select and autofill the "CourseFee" field based on the date.

If the date is prior to the one above, I want a value (Under25) to autofill.  If the date is later than the one above, I want the value (Over25) to autofill.

Is this doable?

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

41

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

Under25 and Over25 are younger or older then 25years?

Why select 01/01/1996? If someone is born 01/01/1996 in one month your calculation will be wrong they would be Over25 and your calculation will show it's Under25.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

LATEST

First of all, as mentioned, the age depends not only on the DOB, but also on the current time... But what you described can be achieved using the following code as the custom calculation script of "CourseFee":

 

var dobString = this.getField("DOB").valueAsString;
if (dobString=="") event.value = "";
else {
	var dob = util.scand("mm/dd/yyyy", dobString);
	var cutOffDate = new Date(1996, 0, 1);
	event.value = (dob.getTime()>=cutOffDate.getTime()) ? "Under25" : "Over25";
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines