Print Page | Close Window

run function the instant combobox value changes

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 08 Dec 2019 at 7:38pm
Software Version: Web Wiz Forums 11.10 -

Topic: run function the instant combobox value changes
Posted By: morrison
Subject: run function the instant combobox value changes
Date Posted: 11 Apr 2017 at 4:51pm
Good morning.

I'm trying to get a function that populates text fields to run the moment a combobox's selection changes, not after the user clicks in another form field.  Is this possible?

Each unique option in the combobox will populate a name in one text field and a number in another text field.  Since this has to work for returning users who already have a value saved in the combo box, the function is at document level, and the call to the function is on page1>open.  That works beautifully for returning users who have a previously-saved selection in the combobox. 

However, I also need it to work if the user has no previous selection, as well as when the combobox selection is changed.  We will have users who are going in the form solely for the purpose of changing the selection and jumping directly to the save button.  Therefore, they are not expecting to have to click in another field to see their new selection change the values in the name and number text fields.  They're going to panic and not want to click save.

Things I've tried:
  • applying the script to various mouse triggers in the combobox -- works, but users have to click in another form field to effect change
  • custom keystroke -- values displayed are old news (stale, meaning only event related to previously-clicked selection occurs)

Here are the custom keystroke scripts that triggered the stale values populating:

if(event.willCommit) {
  if(event.value == "" | event.value=="Select a code") this.resetForm(["agency_name","agency_tin"]);
  else populateAgency();

// and the other

if(!(event.value=="") && !(event.value=="Select a code")){

if(event.value=="" | event.value=="Select a code"){

P.S. - I do have "commit selected value immediately" selected.

Any ideas, or is there just not enough control over time of execution to make the field value change happen instantaneously?

Thank you,


Posted By: Rob Lyman
Date Posted: 12 Apr 2017 at 8:58pm
Bear in mind that at the moment the keystroke script is being run, the field's value may not have been updated yet. In other words, "field.value" will hold the previous value, but "event.value" will hold the new (i.e. candidate) value.

This could explain why you are seeing 'stale' values in the other fields: you appear to be calling a method that will update those fields, but the new values are not passed as arguments; I assume you're reading them from the "field.value", which may not yet be updated.

Note, however, that Acrobat's behavior can be different when "event.willCommit" is true in the keystroke script. I'd advise printing information to the console (use console.println()) to make sure you're getting the data you expect.

Rob Lyman
Software Engineer

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -