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

How can I sum values from different fields?

clueless1942
Registered: Jun 14 2010
Posts: 23
Answered

Hello,

I'm a new user to LCD, and also new to JS. I was redirected here from the Javascript forums.

[i]Hello,

I'm just starting to learn JS, to make some simple scripts for my PDF presentations and forms.

I'm trying to sum different values from a couple of dropdown lists, and showing it in another field:

xfa.resolveNode("form1.page1.NumericField3").rawValue = xfa.resolveNode("form1.page1.DropDownList2").rawValue + xfa.resolveNode("form1.page1.DropDownList3").rawValue + xfa.resolveNode("form1.page1.DropDownList4").rawValue;

I think it is treating the values as strings, cause if the values are 2, 3, 4 the sum field displays 234.

What am I doing wrong? (another user has told me that there's a sum function in LCD, but I don't know how to use it, would someone point me?

And: where is the best (free) document to start learning JS from the basics?

Thank you

PS: Sorry about my poor english, in case I made some bad spelling[/i]

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
I replied to your first post. Have you tried the use of the 'Sum()' function that I mentioned?

George Kaiser

clueless1942
Registered: Jun 14 2010
Posts: 23
Sorry, I thought you wanted me to ask here.

I've tried with the sum function you showed me:

xfa.resolveNode("form1.page1.NumericField3").rawValue =  sum(xfa.resolveNode("form1.page1.DropDownList2").rawValue,xfa.resolveNode("form1.page1.DropDownList3").rawValue,xfa.resolveNode("form1.page1.DropDownList4").rawValue);
but it's only valid when using Formcalc, and I'm trying to do the whole work under JS because I may reuse the code for exporting to HTML in the future.

I'm sure that there must be a way to do this in JS, isn't it?

Thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Acrobat JavaScirpt is not fully compatible with Web JavaScript. 'resolveNode' and 'rawValue' are not in JavaScript.

You can write your own 'Sum' function in JavaScirpt and you can use the isNaN to test for non-numeric values and the Number constrictor to force nulls to zero.

See [url=https://acrobat.com/#d=BTBoKOwsJb0KdpT-*8SZqw]Sum vs. Plus[/url] for an example in AcroForms. The document level function will work in LiveCycle Designer.

George Kaiser

clueless1942
Registered: Jun 14 2010
Posts: 23
Thank you so much!!!!

I didn't know that Acrobat JS and Web JS were not exactly the same.

I've just checked the "sum" function in the linked pdf, and I think I could write myself something similar. Just one little question more: when I build the arrays of values, how should I refer to them?

Is it correct with just a simple ("form.page.object1","form.page.object2", etc) or should I use

(xfa.resolveNode"form.page.object1",xfa.resolveNode"form.page.object2", etc)?


As you see, the thing that confuses me most, is the way I must refer to objects in the script.

Anyway, thank you again for your great help!!