Skip to main content
Participating Frequently
June 20, 2017
Answered

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

  • June 20, 2017
  • 1 reply
  • 461 views

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!

This topic has been closed for replies.
Correct answer try67

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;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 20, 2017

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;

Participating Frequently
June 20, 2017

Thanks! This worked perfectly.