3

I'm not a newb to JavaScript but this is my first foray into Acrobat Scripting.

What I'm trying to do is change a text field based on the value selected in a comboBox.

Since I have many different comboboxes with the same set of options, and many text fields that are supposed to be bound to those, I would prefer a document scope function that could be reused for all of those.

I'm not sure if this is possible but here's what I'm thinking...

Detect when a combo box is changed. On the change event submission, take the export value from that and make it the value for the related text field.

Here's the steps:

  • capture combo box onmouseup event
  • detect which combo box triggered the event
  • match up the name of the combo box to its associated text field using an array listing
  • use a getField() to fetch the text field
  • set the text fields value to be the export value of the combo box

Any help with this would be appreciated. Especially good sources about Acrobat event triggers and how they work. I have been through a great deal of the API documentation and can't find anything on it.

Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
  • If you can use jQuery things will be pretty simple - so can you? – Shadow The GPT Wizard May 13 '11 at 23:07
  • Nope. Acrobat scripting isn't the usual JavaScript. If it was, I wouldn't have this issue. Think of it as a bare bones JS interpreter with a different DOM (there are actually 3 different DOMs in PDFs). – Evan Plaice May 13 '11 at 23:16
  • so plain JavaScript with `document.getElementsByTagName` will work? – Shadow The GPT Wizard May 14 '11 at 07:39
  • @Shadow No, in Acrobat it would actually be this.getField("fieldName") or doc.getField("fieldName"). But, that's not the issue I'm trying to address here. I'm asking if there is a way to subscribe to field events from document scope. If you take a look at the Javascript API for Acrobat you'll find that, while the language is the same, the architecture is much different from the standard HTML DOM/JS model. What I'm looking for is somebody who is experienced in Acrobat development who may be able to answer this. – Evan Plaice May 16 '11 at 15:46
  • I see.. thought it was more close to the "ordinary" JavaScript sorry. Hope someone will come by! :) – Shadow The GPT Wizard May 16 '11 at 19:07

1 Answers1

4

Found it!

After exhaustive hours/days of Googling I finally found a solution that works.

The handler function needs to be bound to the 'Keystroke' event.

The handler function should contain:

if(!event.willCommit) {
  this.getField('[field]').value = event.change;
}

Note: Where 'field' is the name of the field being updated and event.change is the value selected in the combobox.

To fetch the export value of the selection use the following:

if(!event.willCommit) {
  this.getField('[field]').value = event.changeEx;
}

Apparently, 'Keystroke' is fired any time a UI element is interacted with. If you don't want it to execute when the document loads, be sure to bind the handler function to the event during the page load event.

Thoughts: AcroForms JS (Javascript for Acrobat) has a seriously broken event model. If you were to get the value of the combobox while using this even handler it would serve up a stale value. Not only does it take an obscure hack to make it work but there is little/no AcroForms JS community to provide answers to hard questions like these.

Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
  • Dude.... I've also come this far but I need to go a little further. Can you please take a look at this.... http://stackoverflow.com/questions/43914342/get-values-from-array-with-event-change – Interactive May 11 '17 at 12:11