Skip to main content
Known Participant
March 5, 2025
Answered

Trying to display a picture based on variable criteria

  • March 5, 2025
  • 1 reply
  • 1194 views

Hello, 

I'd like to display Image1 if a field totals a score between 48 and 54, display Image2 if a field totals a score greater than or equal to 55, and hide both images if they don't meet that criteria. I've tried with a the image as a Button and as a straight-up image. I can't get it to work where they're hidden unless they meet that criteria OR to display if they DO meet either criteria.

 

Please help. 🙂

Correct answer PDF Automation Station

You can see it in the Prepare Form view- it's hidden on the actual form.


I had the wrong form.  My previous script would work if it was comparing the value to the ScoreField field instead of the Total field.  I also works if entered into the total field.  There's another another way to do it by using only one image field, and changing the icon it you're interested:

https://pdfautomationstation.substack.com/p/how-to-build-a-pdf-button-image-carousel

1 reply

PDF Automation Station
Community Expert
Community Expert
March 5, 2025

Enter the following custom calculation script in the text field:

if(event.value >= 48 && event.value <= 54)

{

this.getField("Image1").display=display.visible;

this.getField("Image2).display=display.hidden;

}

else if (event.value >= 55)

{

this.getField("Image1").display=display.hidden;

this.getField("Image2).display=display.visible;

}

else

{

this.getField("Image1").display=display.hidden;

this.getField("Image2).display=display.hidden;

}

 

This does not account for numbers greater than 54 and less than 55.  If your results are whole numbers then there's no issue.

try67
Community Expert
Community Expert
March 6, 2025

Just to clarify, the above assumes the images are used as the icons of image (actually button) form fields... You have to set that up first, and then the code above will work.

Known Participant
March 6, 2025

It's like magic! I have GOT to learn to code. Thank you SO much!!!