Is there a way to apply the following code to multiple fields? In other words, could this be set as document level code that applies to multiple fields instead of having the code in each form field? My form is getting sluggish, it take 4-5 seconds after filling in data to tab to the next field, so I'm trying to cleanup the code.
var TotalTime=this.getField("GRAND TOTAL").value;
if(event.value>TotalTime)app.alert("Cannot Exceed Total Time")
if (event.value==0.0) event.value = "";
//This code is in fields “1 Time”, “2 Time”, “3 Time”, etc.
Yes you can do that, but if your PDF is sluggish it won't make a difference if you call the function from those fields as a custom calculating script.
Instead, you should call the function with a mouse-up event action or Custom Keystroke Script. Doing so will only call the function and execute the script when is really needed instead of a a script looping in the background continuously when used a custom calculation.
For example, if the GRAND TOTAL field is the field that contains some heavy calculations use that script as a document-level function oand call that function from that field with a mouse-up event. The user must click inside and outside the GRAND TOTAL field to execute the calculation though.
Then the code that you posted here use it as a validation script instead of a custom calculating script.
These are just ideas.
Everyone has different approaches or knowledge on how to obtain similar results.
Using a combination of fields with mouse-up events, checkboxes, dripdown menus, and custom keystroke script can make the PDF fly. You would be surprised with the speed.
Under what event did you place this code? Assuming it's a Validation script, that's not what causing your form to be sluggish, as it only executes when you change the field's value. Calculation scripts are typically what causes that, as they are executed when the value of any field in the file is changed.
I'm a novice, so I'll try to answer your question as best as possible. The code is in the Validation script of fields "1 Time”, “2 Time”, “3 Time”, etc. However, there are a lot of other fields that have script in Custom Calculations which it sounds like I should move to Validation, when possible.
Calculation and Validation are quite different, but if you can move code from the latter to the former it will help your form work faster, yes.