These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

why script can not go back to 0 and re-enter it?

andrewchow11
Registered: Mar 28 2011
Posts: 20

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?

My Product Information:
Acrobat 9.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Does your code ever show the sums less than 100?

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

andrewchow11
Registered: Mar 28 2011
Posts: 20
thanks gkaiseril,

I have modified script, as follows:
Step1 -> In T1 textbox input 9
Step2 -> In T2 textbox input 99(more than 100)There will be pop-up alert message(Correct),
but there is not clear "T2 value" and re-enter T2 field again,
and jump directly to the T3 field??