hi, I created three textbox(T1/T2/T3), and enter numbers,
When the sum of the three textbox over 100,
there will be alert message, return event.value to '0',
after that re-enter number.
//the total is larger than 100
var sum = 0;
var aFields = new Array("T1", "T2", "T3");
for(i = 0; i < aFields.length; i++) {sum += Number(this.getField(aFields[i]).value);}
if(sum > 100) {
app.alert("not larger than 100");}
event.value = '';
But why script can not go back to 0 and re-enter it?
Adding comments to the code and a little reformatting might show the issue:
//the total is larger than 100
var sum = 0;
var aFields = new Array("T1", "T2", "T3");
for(i = 0; i < aFields.length; i++) {
sum += Number(this.getField(aFields[i]).value);
} // end for fields loop;
if(sum > 100) {
app.alert("not larger than 100");
} //end if sum > 100 block of code
event.value = ''; // force field value to null;
I see no code that sets the field to the value of the sum.
It is also now clear that the field's value is always forced to a null value.
Try:
//the total is larger than 100
var sum = 0;
var aFields = new Array("T1", "T2", "T3");
for(i = 0; i < aFields.length; i++) {
sum += Number(this.getField(aFields[i]).value);
} // end for fields loop;
event.value = sum; // set field to value of sum;
if(sum > 100) {
app.alert("not larger than 100");
event.value = ''; // force field value to null;
} //end if sum > 100 block of code
George Kaiser