addScript() on selection change, PDF-XChange PRO

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
bjorklundr
User
Posts: 4
Joined: Mon Dec 18, 2017 12:51 am

addScript() on selection change, PDF-XChange PRO

Post by bjorklundr » Tue Aug 06, 2019 5:20 pm

Building an interactive survey form, where fields appear or disappear based on selections made by user.

Step 1: User selects one, two, three, or four categories from a list of six (check boxes). If the user checks two boxes (of six), one tailored radio-button groups appears. If user checks three boxes, three radio-button groups appear. Checking four boxes makes six tailored radio-button groups appear. If only one category is selected, no radio-button groups are needed.
Step 2: User clicks radio buttons in each group that has appeared, indicating his/her preferences. The user must select a radio button in each of the groups in order to record his/her preferences and visualize the results.
Step 3: Upon validating that the user has selected a radio button in each of the 1, 3, or 6 radio-button groups, I would like the calculations to begin and then display the results to the user before allowing him/her to move to the next page.

Since the radio-button groups do not exist when the document is first opened, I don't know a way to attach or assign a script to them that validates the input and triggers the calculations and results display. I need to add a script that records the radio button selections and computes the answer (using a script I have already written and successfully tested).

The most straightforward solution would be to include the addScript() function to each check-box mouse-up script (that would in turn attach a script to the each of the added radio-button groups). Indeed, addScript() works well in PDF Xchange Editor; the calculations start and the results display after input validation. But Acrobat Reader DC (which most survey respondents will use) does not permit execution of the addScript() (or setAction()) function for security reasons.

What would be another approach to automatically execute a script that reads and displays what the user has selected in the variable number of radio-button groups added during runtime to the survey form?

Attachments include a sample form (formsExperimentRadio1) and the calculation script (formsExperimentRadio1scriptA) (which must be run in the XChange JavaScript Console to see the intended results of the form and the visualization).

Thanks in advance.

PDF-XChange Editor Plus V8 Build 331.0; Windows 10
Attachments
formsExperimentRadio1scriptA.7z
(1.73 KiB) Downloaded 1 time
formsExperimentRadio1.7z
(7.29 KiB) Downloaded 3 times

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: addScript() on selection change, PDF-XChange PRO

Post by Tracker Supp-Stefan » Wed Aug 07, 2019 2:55 pm

Hello bjorklundr,

Would an alternative approach solve your problem?
You can create the radio button groups, and have them hidden by default.
The user then toggling the check boxes would show or hide them as needed.

You would in that case be able to have the script added to radio groups without needing to add it at run time!

Then when running your validation - you will e.g. check which radio groups are hidden and which are shown, and only validate values in the visible groups.

Do you believe this will work for you?

Regards,
Stefan

bjorklundr
User
Posts: 4
Joined: Mon Dec 18, 2017 12:51 am

Re: addScript() on selection change, PDF-XChange PRO

Post by bjorklundr » Wed Aug 07, 2019 3:25 pm

Stefan,

Thank you very much for looking at this and for your guidance. I have now run a couple of tests using the hidden/visible parameter, and your suggested approach seems to work fine in Acrobat Reader. (I probably needed to rewrite the inefficient code anyway!)

Solved.

Regards,
bjorklundr

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: addScript() on selection change, PDF-XChange PRO

Post by Tracker Supp-Stefan » Thu Aug 08, 2019 10:56 am

Hello bjorklundr,

Glad to hear that you managed to get your form working the way you need it!

Cheers,
Stefan

Post Reply