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

JavaScript to run on open

New Here ,
Oct 14, 2022 Oct 14, 2022
Hello! Needing some JavaScript coding help on an Adobe dynamic form. Does anyone know a code that will do the following on an adobe form (with layers).
 
Upon open, set layer visibility to last save
or
Upon open, find selected radio button and re-run code that lives under that selection
 
Currently the form functions as below:
  • viewer selects a radio button option 1,2, or 3
  • the corresponding layer becomes visible, along with all form functions like text boxes, check boxes, etc. that correspond with the selected layer.
  • viewer fills in the form and saves it
  • reviewer opens the form and instead of seeing how the form was last saved, it reverts back to the original view of the form (which is option 1). The reviewer then has to reselect (let's say option 2) on the radio button to view it correctly.
I believe there is a code that I could write upon document open to either view the radio button and rerun the code on that, or to open with layer visibility last saved. I don't know enough about JS to know that. Any help/advice is much appreciated, thank you in advance!!
TOPICS
JavaScript , PDF forms
1.4K
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 ,
Oct 14, 2022 Oct 14, 2022
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 ,
Oct 14, 2022 Oct 14, 2022
LATEST

I think that you can achieve the form behavior you want. But it's not simple. 

Code on form fields is driven by events, such as clicks and data changes. The Acrobat JavaScript model does not provide functions for trigging these events artificially, except for the Calculate event. The best way to share script functionality is to put that functionality into a function defined in a document level script. Then call the function whereever it is needed. 

 

All the code in a Document level script is run when the PDF is opened.  So you can use it to define shared data and functions, and to run document initialization code. 

 

Here's an article on the topic:

https://www.pdfscripting.com/public/Document-Level-Scripts.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