Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Selecting checkbox to show/hide images upon Selection

Community Beginner ,
Jan 26, 2023 Jan 26, 2023

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?

TOPICS
General troubleshooting , JavaScript , PDF forms
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 26, 2023 Jan 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

Where does you use the script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2023 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

When you display a button hide the other buttons.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2023 Jan 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

Hide a button :

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

Use it at the checkbox. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2023 Jan 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023
LATEST

Have you cleared the console?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines