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

Toggle between layers with radio buttons with Javascript

New Here ,
Nov 18, 2021 Nov 18, 2021

I'm making a interactive document ( ‘selector' ) in Indesign that shows/filters the images available as a result of selecting 3 radiobutton groups.

 

Depending on the selection of group 1, (filtered with the radio button) I have a filtered selection in group 2, and that gives a filtered selection for group 3

 

How do I get this to work with a javascript (layers?, Show/hide field? , IF, then?)

 

Hope you can help 😄

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms
2.6K
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
New Here ,
Nov 18, 2021 Nov 18, 2021
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 ,
Nov 18, 2021 Nov 18, 2021

Here's an article that describes how to use Layers (OCGs) in a script.

https://acrobatusers.com/tutorials/create_use_layers/

 

You can find out more about scripting radio buttons here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Nov 19, 2021 Nov 19, 2021

Thanks for the answer and I have read through your reference. But since my javascript level is at beginner, I still can't quite figure it out. 😞

 

What I have done now with radiobutton group 1 and 2, the group with image (buttons) filter separately per radiobutton group

 

Radiobutton group 1
this.getField("choice 1").display = display.visible;
this.getField("choice 2").display = display.hidden ;
this.getField("choice 3").display = display.hidden ;
this.getField("choice 4").display = display.hidden ;

 

radio button group 2
this.getField("choice A").display = display.visible;
this.getField("choice B").display = display.hidden ;
this.getField("choice C").display = display.hidden ;

And that works perfectly

 

But now I want to use the same radio buttons to filter in combination with selection (radio button group1 & 2) in addition to stand-alone.

Radiobutton 1 + Radiobutton 2; = Choice C

 

Is this posible?

Is that with "if, then" or "if, else"?

Would be great if I have an example/snippit to make it more clear for me?

 

Thanks 

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 ,
Nov 19, 2021 Nov 19, 2021
LATEST

So by "Layers" you mean images on a button?  These details are really important. But glad you were able to get through the first bit. 

Here's another article:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

 

The logic to accomplish these selections is on the complex side. What you need to do is create a decision matrix. i.e. what images are displayed for every single combination of radio button selections. The logic in the script is then derived directly from this.   

 

There are several different ways to script this kind of selection logic. Yes, it could be done with if/else blocks. It could also be done with calculated logic, or by creating a selection object that paralells the decision matrix.  The best method to use depends on the complexity of the selections and your abilities.  I'd say that for this, the seleciton object is probably the best choice.   But here's an example that uses if/else if blocks  (this script is by no means complete or correct in any way. It just shows the shape of a possible solution. 

var cColor = this.getField("RadioColor").value;
var cNumber = this.getField("RadioNumber").value;
var cShape = this.getField("RadioShap").value;

if(cColor == "Red")
{
    if(cNumber == "1")
    {
        if(cShape == "Circle")
        {
            this.getField("Something").diplay = visible;
        } 
        else if(cShape == "Square")

and so forth

 

 

 

  

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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