I created a "CalcOverride" checkbox and entered your code in "Text1" to see if it would work but it still auto populates if "CalcOverride" is checked or not. Any suggestions?
That's because of how the calculation script is written.
First, always return the calculated value for a field in the "event.value property".
So replace this line:
this.getField("Text1").value = total1;
with this one:
event.value = total1;
Next, since the script aslo sets a value in a different field, the entire calculation has to be qualified in order to allow user entry into the "Text2" field.
So put the whole calculation into an "if" statement
event.rc = this.getField("CalcOverride").value != "Off";
if(event.rc)
{
..... calculation script ...
}
There are a few other things that could be improved with this script. For example, the data could be moved to a document level script so it's global to the entire document. And the loop for finding the matching data could be simplified by useing the Array.find() method.