I was trying to sum value through array in JavaScript calculation event. But the value is not added rather the value places side by side (output 111 but it should be 3)
var aList = new Array(xfa.resolveNode("A"),xfa.resolveNode("B"),xfa.resolveNode("C"));
j = NumericalField.rawValue;
total = 0;
for(var i =0; i<j; i++)
{
total = total+aList[i].rawValue;
}
this.rawValue = total;
Above script cannot add the value just showing 111 instead of 3.
How can I solve it?
Solved! Go to Solution.
Views
Replies
Total Likes
Also when adding fields with 'rawValue' in JavaScript you run the risk of inadvertantly concatenating strings together, in your case '111'. You need to convert it to a number first by either using parseInt or parseFloat.
For example, total = total+parseInt(aList[i].rawValue); from your original post.
Kyle
Views
Replies
Total Likes
Hi,
may I als if you use an array. Normally you don't need an array for an addition.
This script makes an addition from all fields called "summe". Change this if you field name is amount to amount.
var page = xfa.layout.page(this)-1;
var fields = xfa.layout.pageContent(page , "field", 0);
this.rawValue = 0;
var total = 0;
for (var i=0; i <= fields.length-1; i++)
{
if (fields.item(i).name == "summe")
{
total = total + fields.item(i).rawValue;
}
}
this.rawValue = total;
Here you will find an example. https://workspaces.acrobat.com/?d=PtkT0VkRuIsKJOgnmagKWw
Hopefully helpful, (if not maybe you could insert a screenshot from your scenario?)
Mandy
Thanks for your response.
Actually the field name must be unique and always all fields(500 fields) value will not add. And that is why I used array and j value will control the no of field from array.
I do not understand why my script do not add rather it gets value side by side.
In result field I get 111 insted of 3 but it should be 3.
Thanks
Views
Replies
Total Likes
You have the possibility to upload your formular anywhere?
Views
Replies
Total Likes
Here is the file.
https://dl.dropbox.com/u/70850345/Work/Summation.pdf
I think dropDown field value resist to add.
Views
Replies
Total Likes
You have posted a nice and convenient script. If I want to add fields value in different pages or in different subform, what will be script?
Thanks
Views
Replies
Total Likes
You have to add nothing. The script looks for all pages and alle fields called summe and make an addition of them.
I see you have no number fields for the addition. you want to make an addition from a lot of dropdown fields, right?
If I right then you have to use the following simple thing.
rename all your dropdowns - for example DDL -
in the total field you select as language "Formcalc"
and use this script in the calculate event
$ = Sum(DDL[*])
https://workspaces.acrobat.com/?d=tSNfzRZXkOG5azk4I1*mFw
Helpful?
Mandy
Also when adding fields with 'rawValue' in JavaScript you run the risk of inadvertantly concatenating strings together, in your case '111'. You need to convert it to a number first by either using parseInt or parseFloat.
For example, total = total+parseInt(aList[i].rawValue); from your original post.
Kyle
Views
Replies
Total Likes
Nice solution.
Getting problem until enter all three fields, I can not get result.
If I select the 1st dropDown, the result will be 1 but not get result after selecting 1st one.
How can I solve it?
Views
Replies
Total Likes
Views
Likes
Replies