Copy link to clipboard
Copied
Let’s say I have three sets of variables:
Large, Medium, Small.
Red, White, Blue.
Cat, Dog, Fish.
I want to assign a set of radio buttons to each row. The user would make one choice within each row and, depending on what the three choices were, would jump to a specific page in the document. So, if they choose Small Red Dog they’re sent to page 22, if they choose Medium Blue Fish they’re sent to page 16, etc.
But now I don’t know how to proceed. How do I tell Acrobat to jump to a specific page based on specific radio button choices?
Copy link to clipboard
Copied
You may be able to achieve this by doing the following:
Copy link to clipboard
Copied
This won't work for what they described. You would have to use a script with conditional logic to check the state of all three radio-button groups so you could decide which page to go to. If you use the "Go to a page view" command it's hard-coded and can't be made conditional on other factors.
Copy link to clipboard
Copied
You're right, I missed the conditional part completely which depends on thre choices made.
This brings me to another question: How many sets of radio buttons are assigned to each row?
Copy link to clipboard
Copied
This is a bit tricky to implement, and as I wrote above, it will require using a script.
The way I would do it is by using a (hidden) text field to concatenate all the values from the radio-buttons and then decide which page to go to (if at all) based on that string. In order to do that you can use the following code as that field's custom Calculation script:
event.value = this.getField("Group1").valueAsString + " " + this.getField("Group2").valueAsString + " " + this.getField("Group3").valueAsString;
if (event.source && (event.source.name=="Group1" || event.source.name=="Group2" || event.source.name=="Group3")) {
if (event.value=="Small Red Dog") this.pageNum = 21; // Go to page 22
else if (event.value=="Medium Blue Fish") this.pageNum = 15; // Go to page 16
// etc.
}
You will need to adjust the field names in the first two lines so that they match the actual names in your file, since you didn't specify them in your question.
Copy link to clipboard
Copied
Thank you all for taking the time to respond. I know very little about JS so while I take the time to parse out your recommendations, I want to mention that a direction that occurred to me was to assign a different numerical value to each radio button so that the sum of any possible combinaiton would result in a unique number. E.g,
100 to Large, 200 to Medium, 300 to Small,
10 to Red, 20 to White, 30 to Blue,
1 to Cat, 2 to Dog, and 3 to Fish.
(Medium Blue Fish would be 233, Small Red Dog would be 312, etc.).
So I would tell Javascript- If the sum = 233, jump to page 16, etc. I just don't know how to program that "jump here if you see this number" function.
Copy link to clipboard
Copied
@try67: I copied and pasted your code into the JS field in the Prepare Forms tool and got a Syntax Error (Missing ;). I've uploaded a rough PDF with the three groups of radio buttons installed. If you have time could you try to implement your solution in that doc?
Copy link to clipboard
Copied
Did you edit it in any way, because there's no such error in the code I posted.
I also don't see where's the text field you were supposed to add and place the code under...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That works beautifully. Thank you. I must have copied it wrong. Can you confirm that subsequent lines would look like this:
if (event.value==”Small Red Dog”) this.pageNum = 21; // Go to page 22
else if (event.value==”Medium Blue Fish”) this.pageNum = 15; // Go to page 16
else if (event.value==”Medium Red Fish”) this.pageNum = 16; // Go to page 17
else if (event.value==”Medium Green Fish”) this.pageNum = 17; // Go to page 18
Copy link to clipboard
Copied
Correct. But you don't need to add the comments, of course...
Copy link to clipboard
Copied
Now I must expose how little I know javascript: Which parts are comments?
Copy link to clipboard
Copied
The text after // .
Copy link to clipboard
Copied
Also, I noticed you used curly quotes ( ” ” ) in the code you posted above. That won't work.
You must only use straight-quotes ( " " ). Do NOT use Word to edit the code, if that's what you're doing. Only use a plain-text editor. I recommend Notepad++.
Copy link to clipboard
Copied
Yeah, the quote marks were defaulting to "typographers quote marks" which I fixed, thanks.
One more issue: When I open the file in Reader, the buttons which are part of a group have the blue field highlight fill. They don't have that in Acrobat. And the buttons which are not part of a group do not have the blue in Reader. I have "Highlight existing fields" and "Show border hover color for fields" both unchecked. Any ideas?
Copy link to clipboard
Copied
This is a setting of each application, not of the file, although you can embed a script in your file to turn this setting on or off.
Copy link to clipboard
Copied
I see. Will I be wearing out my welcome to ask you what that script would look like?
Copy link to clipboard
Copied
No, but I should warn you that if you do embed this code in your file it will disable the Fields Highlighting for all the files the user opens after viewing it, so it might be a good idea to warn them about it, or get the approval for making this change to their application. Do you want to enable or to disable it?
Copy link to clipboard
Copied
Actually, nevermind. I'll just advise the users to manually hide the field color.
Thanks again for all your help.
Copy link to clipboard
Copied
That's a good idea. You can do that with a script, too, though.
Something like this (as a doc-level script):
if (app.runtimeHighlight) app.alert("It's recommended to turn off fields highlighting to view this file correctly.",3);
Copy link to clipboard
Copied
That's a great idea. BTW, what does the comma-3 do in this line?
Copy link to clipboard
Copied
It determines what icon will be used in the alert window. 3 stands for the "Information" icon (a "i" inside a blue circle).
Copy link to clipboard
Copied
Time for me to study JS. Any recommendations where to start?
Copy link to clipboard
Copied
Note that this is Acrobat JS, and most tutorials online are for web-based JS. While the two share a common syntax, almost everything else is different.
Here are some good resources to get you started:
General JS tutorial: http://www.w3schools.com/js/default.asp
Homepage of the Acrobat SDK, including a link to the full API: http://www.adobe.com/devnet/acrobat.html
Free tutorials about Acrobat in general, including many JS related ones: https://acrobatusers.com/tutorials/
A paid-for website with tutorials about Acrobat JavaScript (not related to me): http://www.pdfscripting.com/
My own humble web-site with many tools for Acrobat and Reader (mostly paid-for, some free): http://www.try67.com
Copy link to clipboard
Copied
Perfect.
Until next time...