How to show/hide "field Z" if "field Y" is within 10 digits of "field X"?

New Here ,
Jun 20, 2017

Copy link to clipboard

Copied

I'm trying to create a form that determines if a patient requires a particular lab based on their history. "field X" is the patient's age and "field Y" is another age. I'm trying to create a script that determines if "field Y" is plus or minus 10 years of the age in "field X". If it is within 10 years I want "field Z" to show. If the age isn't within 10 years, then I want "field Z" to remain hidden.

I'd appreciate any help with this. I'm almost done with this form and it's looking great so far. Thanks in advance!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Enter this code as the custom calculation script of "Z":

var x = this.getField("X").valueAsString;

var y = this.getField("Y").valueAsString;

if (x=="" || y=="") event.target.display = display.hidden; // if either field is empty, hide this field

else event.target.display = (Math.abs(Number(x)-Number(y))<10) ? display.visible : display.hidden;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

78

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

How to show/hide "field Z" if "field Y" is within 10 digits of "field X"?

New Here ,
Jun 20, 2017

Copy link to clipboard

Copied

I'm trying to create a form that determines if a patient requires a particular lab based on their history. "field X" is the patient's age and "field Y" is another age. I'm trying to create a script that determines if "field Y" is plus or minus 10 years of the age in "field X". If it is within 10 years I want "field Z" to show. If the age isn't within 10 years, then I want "field Z" to remain hidden.

I'd appreciate any help with this. I'm almost done with this form and it's looking great so far. Thanks in advance!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Enter this code as the custom calculation script of "Z":

var x = this.getField("X").valueAsString;

var y = this.getField("Y").valueAsString;

if (x=="" || y=="") event.target.display = display.hidden; // if either field is empty, hide this field

else event.target.display = (Math.abs(Number(x)-Number(y))<10) ? display.visible : display.hidden;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

79

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
Jun 20, 2017 0
Most Valuable Participant ,
Jun 20, 2017

Copy link to clipboard

Copied

Enter this code as the custom calculation script of "Z":

var x = this.getField("X").valueAsString;

var y = this.getField("Y").valueAsString;

if (x=="" || y=="") event.target.display = display.hidden; // if either field is empty, hide this field

else event.target.display = (Math.abs(Number(x)-Number(y))<10) ? display.visible : display.hidden;

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
Reply
Loading...
Jun 20, 2017 0
New Here ,
Jun 20, 2017

Copy link to clipboard

Copied

Thanks! This worked perfectly.

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
Reply
Loading...
Jun 20, 2017 0