Copy link to clipboard
Copied
I have a code and it's sort of working, here is my problem, I'm calculating totals with a loop and I want to show result in first field that is empty, I managed to make this work but it shows result in all empty fields not just first one that is empty and it's doubling result.
here is example file:
https://drive.google.com/uc?export=download&id=1g7UKiR3Zln0ngn5czrXCfdLtDgliZop6
Code is in "t10" field.
Try this:
var tot = 0;
var to2 = 0;
for (var i=1; i<=10; i++) {
if(this.getField("t"+i).value != "")tot++;
var f = tot+1;
if (this.getField("Text"+i).value!= "" && this.getField("p"+i).value != "") {
this.getField("t"+i).value = Number(this.getField("Text"+i).value) *
Number(this.getField("p"+i).value);
to2 += Number(this.getField("t"+i).value);
this.getField("t"+f).value = to2;
}
}
Info: The field with the name p7 doesn't exists.
Copy link to clipboard
Copied
There are errors in your code. Check the JS Console.
Copy link to clipboard
Copied
Yes it says: this.getField(...) is null 11:Console:Exec I don't know what that mean, Although the code is working I just want it to populate only first empty field with sum total and not all of them.
Can you point me in right direction?
Copy link to clipboard
Copied
Try this:
var tot = 0;
var to2 = 0;
for (var i=1; i<=10; i++) {
if(this.getField("t"+i).value != "")tot++;
var f = tot+1;
if (this.getField("Text"+i).value!= "" && this.getField("p"+i).value != "") {
this.getField("t"+i).value = Number(this.getField("Text"+i).value) *
Number(this.getField("p"+i).value);
to2 += Number(this.getField("t"+i).value);
this.getField("t"+f).value = to2;
}
}
Info: The field with the name p7 doesn't exists.
Copy link to clipboard
Copied
Wait, what it was just those curly brackets 🙂
Thank you Bernd it's working now .