Skip to main content
johnnyZ
Inspiring
August 14, 2023
Answered

Automatic field fill-in

  • August 14, 2023
  • 1 reply
  • 762 views

To start off with, I’m running Adobe Acrobat 9.0 Standard. 

I know it’s old and outdated, but it’s all I have.

I was recommended to update to version 9.5, but was unable to do that.

 

Description:

I have a PDF fill-in form with different fields. 

The three pertinent to this question are:  Birthdate (DOB), AGE, Is the patient a MINOR?  Yes or No

When the patient enters their DOB, I already have it set to automatically calculate their AGE.

 

Question:

I would also like it to automatically identify whether or not the patient is a Minor.

 

So, if the patient’s age is less that 18 years, YES, the patient is a Minor.

If the patient’s age is 18 years old or more, the patient is NOT a Minor.

 

I don’t care if it uses check boxes with Yes or No, or if there is a field that simply says Minor: YES or NO.

This topic has been closed for replies.
Correct answer try67

That's because it's not the type of code I assumed you used.

Use this:

if (event.value == "") {
    this.getField("Patient Age").value = "";
	this.getField("Minor").value = "";
} else {
    var dob = util.scand("mm/dd/yyyy", event.value);
    var today = new Date();
    var age = today.getFullYear() - dob.getFullYear();
    if (today.getMonth() < dob.getMonth())
        age = age - 1;
    if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate()))
        age -= 1;
    this.getField("Patient Age").value = age;
    this.getField("Minor").value = (age < 18) ? "YES" : "NO";
}

1 reply

try67
Community Expert
Community Expert
August 14, 2023

So you have a calculation script for the age field that calculates the age based on the DOB, right?

At the end of it, add this:

 

this.getField("Minor").value = (event.value<18) ? "YES" : "NO";

 

This assumes there's a text field called "Minor".

johnnyZ
johnnyZAuthor
Inspiring
August 14, 2023

Thanks Try67 for your quick response.

I added your suggestion to the end of my script.

Now regardless of what date I enter as a DOB, I get "NO".

Here's my Custom Validation Script for the DOB field.

if (event.value == "")
this.getField("Patient Age").value = "";
else {
var dob = util.scand("mm/dd/yyyy", event.value);
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
if (today.getMonth() < dob.getMonth()) age = age - 1;
if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate())) age -= 1;
this.getField("Patient Age").value = age;}
this.getField("Minor").value = (event.value<18) ? "YES" : "NO";
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 14, 2023

That's because it's not the type of code I assumed you used.

Use this:

if (event.value == "") {
    this.getField("Patient Age").value = "";
	this.getField("Minor").value = "";
} else {
    var dob = util.scand("mm/dd/yyyy", event.value);
    var today = new Date();
    var age = today.getFullYear() - dob.getFullYear();
    if (today.getMonth() < dob.getMonth())
        age = age - 1;
    if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate()))
        age -= 1;
    this.getField("Patient Age").value = age;
    this.getField("Minor").value = (age < 18) ? "YES" : "NO";
}