Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Change selection in a dropdown
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Change selection in a dropdown

 Post Reply Post Reply
Author
jhmcmullen View Drop Down
New Member
New Member


Joined: 07 Apr 2016
Location: Canada
Points: 5
Post Options Post Options   Quote jhmcmullen Quote  Post ReplyReply Direct Link To This Post Topic: Change selection in a dropdown
    Posted: 31 Dec 2016 at 3:51pm
Okay, I'm not wrapping my head around this.

I have a listbox which contains a space and the numbers one through ten. That works fine; nothing needs to be triggered off the value if they choose a number or zero it out. Currently, the listbox is set to commit the selected value immediately, but

I would like to add a selection item to the listbox, probably a question mark, which randomly chooses a number between one and ten and sets the value of the listbox accordingly.

To me, this sounds like a keystroke or validation function, something like,

if (event.value == "?") {
     event.value = getLevel();
    }

Except doing that doesn't seem to work. (I've tried it as both.) I get just the ? character in the field.

Then I tried going around, and using this.getField("name").currentSelectedIndices to set it, but that didn't work. (getLevel() is written and works fine; I use it elsewhere in the same document.)

So I'm doing something wrong.

It doesn't help that I'm (a) using a different cheaper program to edit the PDF, rather than Acrobat, and (b) I find that my mind is Teflon to the whole set of details regarding events and listboxes, so I end up having to re-learn whatever bit of it I need.

So what should I be doing instead?

Thanks for any help.

John
Back to Top
Sponsored Links


Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4048
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2017 at 4:44pm
Have you looked at the Acrobat JavaScript API and the changeEx property?

Back to Top
Rob Lyman View Drop Down
New Member
New Member
Avatar

Joined: 12 May 2015
Location: Chicago
Points: 20
Post Options Post Options   Quote Rob Lyman Quote  Post ReplyReply Direct Link To This Post Posted: 04 Jan 2017 at 9:41pm
I think what you're seeing is that the 'Selection Change' event (which is what the 'Keystroke' event is called for a list box) is called in two different ways at different points while the user is interacting with the form:

1.) When the user selects an item in the list box, an interim event is fired. This contains the current value (i.e. the value prior to selection) in 'event.value', and the newly selected value in 'event.change'. You can tell it's an interim event because 'event.willCommit' is false.

2.) When the user commits the item (by clicking another form control, or in fact anywhere outside of the list box), a commit event is fired. This contains the newly selected value in 'event.value' and a null in 'event.change'. In this case, 'event.willCommit' is true.

Note that several interim keystroke events may fire before the commit event; this will happen if the user changes their selection before clicking outside of the list box.

To get the effect you want, try first checking the 'event.willCommit' property. If it's true, then change 'event.value', which will replace the list box's value (you may also need to update the current selection index for the list box).
Rob Lyman
Software Engineer
http://www.datalogics.com
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.04a
Copyright ©2001-2016 Web Wiz Ltd.

This page was generated in 0.078 seconds.