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 ![]() |
Author | |
jhmcmullen ![]() New Member ![]() Joined: 07 Apr 2016 Location: Canada Points: 5 |
![]() ![]() ![]() ![]() 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 |
|
![]() |
|
gkaiseril ![]() Senior Member ![]() Joined: 15 Jul 2011 Location: USA Points: 4116 |
![]() ![]() ![]() ![]() |
Have you looked at the Acrobat JavaScript API and the changeEx property?
|
|
![]() |
|
Rob Lyman ![]() New Member ![]() ![]() Joined: 12 May 2015 Location: Chicago Points: 28 |
![]() ![]() ![]() ![]() |
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 |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |