Skip to main content
Participating Frequently
January 26, 2023
Answered

Selecting checkbox to show/hide images upon Selection

  • January 26, 2023
  • 3 replies
  • 3749 views

I've used similar threads to try and troubleshoot my issue but I can't seem to find the answer.

 

Im' working on a company form that has multiple product selections. I've made each checkbox the same name with a different export value so the user can't select multiple checkboxes at once. 

 

I created a button field w/ an image icon to show when each checkbox is selected. The script I used is as follows:

this.getField("Image1").display = (event.target.value=="Off") ? display.hidden : display.visible;

 

The problem is... Even though the user can't select multiple checkboxes at once, multiple images are being shown on the screen. For example, if the user selects the "BOWL 1" checkbox, the correspoding image will appear. But, if the user selects the "BOWL 2" checkbox, the image for "BOWL 1" and "BOWL 2" are being shown even though the "BOWL 1" checkbox is no longer selected. Can someone please tell me what I'm doing wrong?

This topic has been closed for replies.
Correct answer Nesa Nurani

You can put script in hidden text field as custom calculation script, something like this:

this.getField("RFBPic").display = (this.getField("Bowl_es_prefill").valueAsString=="RFB") ? display.visible : display.hidden;
this.getField("RPBPic").display = (this.getField("Bowl_es_prefill").valueAsString=="RPB") ? display.visible : display.hidden;

 

Just continue adding other fields same way.

There is no field "RWBPic" in your file so fix that, also you have a lot of errors in your other scripts, you should check console for errors and fix them all.

3 replies

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
January 26, 2023

You can put script in hidden text field as custom calculation script, something like this:

this.getField("RFBPic").display = (this.getField("Bowl_es_prefill").valueAsString=="RFB") ? display.visible : display.hidden;
this.getField("RPBPic").display = (this.getField("Bowl_es_prefill").valueAsString=="RPB") ? display.visible : display.hidden;

 

Just continue adding other fields same way.

There is no field "RWBPic" in your file so fix that, also you have a lot of errors in your other scripts, you should check console for errors and fix them all.

Participating Frequently
January 26, 2023

Thank you both for the help. I've managed to get the form working as I would like. 

 

For the errors, I've opened the Javascript debugger and I can see what you are talking about. I deleted the scripts causing the errors but the console is showing that the errors still exist. Can you explain why this is?

Bernd Alheit
Community Expert
January 27, 2023

Have you cleared the console?

Bernd Alheit
Community Expert
January 26, 2023

When you display a button hide the other buttons.

Participating Frequently
January 26, 2023

Thank you for the fast replies. Just a few questions:

 

1. Do you mind sharing a simple script for hiding the buttons? I'm not a coder by any means.

2. Do I apply the script to the checkbox or the buttons?

Bernd Alheit
Community Expert
January 26, 2023

Hide a button :

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

Use it at the checkbox. 

Bernd Alheit
Community Expert
January 26, 2023

Where does you use the script?

Participating Frequently
January 26, 2023

If I'm understanding your question correctly, the script was put in the first row of checkbox fields at the bottom of the page. See attached screenshot. Each checkbox has a corresponding field that should be visible when selected.