I want to start off by thanking all those who have helped me directly or indirectly. I'm really new to JavaScript for Acrobat, and was not very familiar with Coding before starting this project.
Now down to what I'm trying to solve.
I have a Text Field that is driven by a ComboBox (Thanks to Thom, I got this working perfectly), and it also has Custom Format Script, Custom Keystroke Script and Custom Calculation Script running on it to provide the functionality that I'm after. This is working exactly as intended until I try to validate what the user is allowed to input, I've tried a variety of ways, and can't seem to get this to work on my own, so I am humbly seeking assistance again.
Here is what I have starting with the Keystroke Script:
if(!event.willCommit) //calling individual keystrokes and selections { event.target.bDetect=true; } else if(event.value=="") { event.target.bDetect=false; }
Then my calculation script:
var Class = this.getField("cmbClass_1").value; //setting variable then calling function <br /> event.rc = !event.target.bDetect; { event.value = Value(Class); }
And finally the script I would like to run, which will validate it as a number and that it fits specific criteria. I can't figure out how to integrate this to make it work properly. I can get it to work, but it'll either prompt me when I select from the ComboBox which drives it or it prompts before the focus is on the Text Field to be validated. I'm sure it probably just a simple solution, and I'm over thinking it at this point, so a fresh set of eyes on this would be wonderful.
event.rc = !/[^-0-9]+/.test(event.value); if (event.value != 6 && event.value != 8 && event.value != 10 && event.value != 12) { app.alert ("Invalid value: Value must be 6, 8, 10, or 12"); event.rc = false; }
=============================================================================================================
=============================================================================================================
New code:
function Sum(nValues) //sum the number of values that are numbers excluding any blanks or nulls <br /> { var nSum = 0 //variable for the sum <br /> for (i = 0; i < nValues.length; i++) //looping through fields { if ((nValues[i] != "") & (nValues[i] != " ") & (!isNaN(nValues[i]))) //testing for blanks, nulls and Not a Numbers console.println ("For i = " + i + " -- nValues = " + nValues[i]) { nSum += Number (nValues[i]) //sums numbers if ((nSum == 0) & (nValues[0] == "")) //testing for zero and null first value { nSum = "" //sums equal zero, setting to null } } } return nSum //returning the nSum value }
However, you are trying to manipulate a complex series of events between two fields. There are two things you need to do:
1. Get a handle on the order of even execution. Place console.println statments in all conditions on all events so you can see what's going on.
2. Simplify the event interaction. If the system is driven entirely from the combobox, then don't use the calculate or keystroke events on the text field.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script