Copy link to clipboard
Copied
I simply want to use a combo box custom keystroke script to call a function when any item is chosen from the box's list. I found many examples and tried many unsuccessfully. My most recent attempt is this:
if(event.changeEx != ""){this.ConcessionMaximum()}
Also tried referencing the export values (there are only three in the list) like this:
if(event.changeEx == "con" || event.changeEx == "fha" || event.changeEx == "va"){
this.ConcessionMaximum();
}
Apologies for what seems a very elementary question, but I would appreciate a solution.
Having export values does not prevent a custom validation script for working for this purpose. You just need to use the display value in the code, instead of the export value.
Copy link to clipboard
Copied
Is there a reason why you want to use keystroke script?
EDIT:
What happens when you use script?
Copy link to clipboard
Copied
Yes, because I want the script to execute when the selection is made. After the selection is made, the cursor is outside of the combo box and none of the other actions work satisfactorily. Nothing happens when I use the keystroke script.
Copy link to clipboard
Copied
Use the Validate event, then. Make sure the option to commit the selected value immediately is ticked under the field's Properties, in the Options tab. This is much better than Keystroke, which will also launch when the user is just scrolling through the list using the keyboard.
The selected value can be referenced using event.value in your code.
Copy link to clipboard
Copied
My objective is to execute the function the instant any item is selected in the combo box dropdown (i.e. before moving the cursor after the selection is made). Placing the suggested script in the Validate event does not accomplish that. I placed the combo box export values in a global array "gTypeProperty" and tried the following script in both a custom keystroke script and Validate event but neither works:
if (!event.willCommit && event.changeEx in gTypeProperty){CommissionMaximum()}.
Copy link to clipboard
Copied
Yes, it does, if you tick the box I described.
Copy link to clipboard
Copied
The option to commit the selected value immediately is ticked and I have this in the Validation event:
if(!event.value == "con" || event.value == "fha" || event.value == "va"){this.ConcessionMaximum()}
Those are the only three export values for the event. When I select an item in the combo box the function is not called.
Copy link to clipboard
Copied
!event.value=="con" should be event.value=="con" (no !). This works. So does my simple keystroke script below. You can also use this validation script:
if(event.target.value!=event.value)
{this.ConcessionMaximum()}
Does your dropdown have export values that differ from the item names?
Copy link to clipboard
Copied
If you have export values it won't work with validate script, try using custom calculation script instead.
Your original script should work fine as keystroke script, are you sure you have right export values, also maybe it's issue in your function script perhaps?
Copy link to clipboard
Copied
Having export values does not prevent a custom validation script for working for this purpose. You just need to use the display value in the code, instead of the export value.
Copy link to clipboard
Copied
Yes, that's what I meant, if he uses export values in script he can try to use custom calculation script since validate won't work, but yes, he can also change to display value to use at validate.
Copy link to clipboard
Copied
I think that we are not understanding each other Nesa, and It appears that everyone mistakenly thought I used a custom calculation script. When I said I achieved my objective I was not using a custom calculation script in the field properties "Calculate" tab. Instead, I placed the ConcessionMaximum() function in the custom format script window [see Properties > Format > Custom > Custom Format Script] (the window above Custom Keystroke Script). Perhaps there is a reason not to use the Custom Format Script, but it seems to work very well for this purpose and, unlike a custom calculation script, a Custom Format Script appears to run only when I choose an item in the combo box list.
The reason my script was not working in the Validation field was as Try67 said, I needed to use the display values represented by the export values, not the export values. Seems odd but it is what it is.
Copy link to clipboard
Copied
The custom format script will run when you open the document, when you click the field, and when you make a selection. If you put the function as a validation script it only runs when the value changes (when a selection is made). You don't need conditions. You only need to place the function there.
Copy link to clipboard
Copied
Thank you for this clarification.
Copy link to clipboard
Copied
Thanks to everyone for your responses. Of the suggestions made, none worked as a Validation event or Custom Keystroke Script. My original script would not work as a keystroke script. My function ConcessionMaximum() works as intended if triggered with actions in other field types.
If by suggesting a "custom calculation script" Nesa Nurani meant "custom format script" under the Format tab, that led to the solution. By inserting only my function - ConcessionMaximum() - as a custom format script, ConcessionMaximum() is called instantly when any item in the combo box list is selected, and that was my objective.
Copy link to clipboard
Copied
A calculation script is not really a good idea. It will launch each time the value of any field in the file is changed.
There's no reason a validation script shouldn't work, as I said before. If you share the file we can help you pinpoint the problem. Just saying "it doesn't work" is not very helpful...
Copy link to clipboard
Copied
I am attaching a PDF with two Dropdown fields. This document has a document level script function, ConcessionMaximum(), which pops an empty alert box. In the first dropdown, the function is called in a validation script and it works. In the second dropdown, it is called in a custom keystroke script, and it works as well. I don't know why it's not working for you.
Copy link to clipboard
Copied
Using a format script is not a good idea, unless you don't mind the function running up to 3x (mouse down, selection, and blur). It also runs as soon as you open the document.
Copy link to clipboard
Copied
Check the Javascript console for errors.
Copy link to clipboard
Copied
Use this keystroke script:
if(!event.willCommit)
{this.ConcessionMaximum()}
Copy link to clipboard
Copied
A validation script runs whenever the value of the field containing the script changes, so all you have to do is enter your function as a validation script. You don't need any conditions. If you don't tick "Commit select value immediately" in the options tab, the function will execute upon the blur event. If you do tick it, the function will execute immediately after making a selection.