Hi, I am building a fillable PDF payment form with LCD and have run into a problem with calculating the sum. I have a 10-Rows table where people can fill-in the prices and I have a another "Total Amount" box that I wish will automaticlly add up the total sum of all the prices. However, after spent nearly an entire week of trying, I can not get it to work....
I am a newbie at this and as of now, I have tried renaming the price boxes into "price1, price2, price3..." and used "Sum=(amount[Price1, Price2, Price3...])" in the Script Editor and I have tried with both languages(javascript/formcalc)..... but everytime when I go to preview, it either tells me that there is an error or the formula just doesn't do anything at all.... I don't understand where did I do wrong. It seems to me that I have done everything suggested on the discussions
Please do help if you can and THANK YOU VERY MUCH!!!!
PS: How do I upload the file?? it would be much easier to understand what I mean if you can see the form yourself.
Solved! Go to Solution.
Views
Replies
Total Likes
From that error message it seems your fields are not in a table, rather just numericfields in a subform. The scripting above will only work in a table. If you just have fields the calculation is just (in formcalc):
$ = price1 + price2 + price3 etc.
If the rest of the fields are in a table and just the calcuation field is not then the calculation needs to be:
$ = sum(TableName.Row2[*].price)
but you need to rename your fields either in the Hierarchy on the left-hand side of your screen or in the Object >Binding > Name tab on the right-hand side. The field in the error message above is called NumericField1[5].
Views
Replies
Total Likes
In a table you will need to reference each row - so your calculation would be something like (in formcalc):
$ = Row1.price1 + Row2.price2 + Row3.price3
or however you have named them. The easiest thing to do is to call each row the same thing (eg. Row1) and each cell in the column the same thing (eg. price) and then you can just do a formcalc formula like this:
$ = sum(Row1[*].price)
The * will take all the rows called Row1 (which will automatically be renamed Row1[0], Row1[1], Row1[2], etc).
Firstly, Thank you very much for your reply!!
I changed the name of all the rows into "row2" at "XML Source" and all the boxes into "price".
but when I used the formula:$ = sum(Row2[*].price) and go to Preview PDF, it told me:
Script Failed (Language is fromcalc; context is
xfa[0].form[0].form1[0].#subform[0].NumericField1[5])
script=$ = sum(Row2[*].price)
Error: accessor 'Row2[*].price' is unknown.
have I not changed the names properly that the system doesn't recognise the boxes??
Views
Replies
Total Likes
From that error message it seems your fields are not in a table, rather just numericfields in a subform. The scripting above will only work in a table. If you just have fields the calculation is just (in formcalc):
$ = price1 + price2 + price3 etc.
If the rest of the fields are in a table and just the calcuation field is not then the calculation needs to be:
$ = sum(TableName.Row2[*].price)
but you need to rename your fields either in the Hierarchy on the left-hand side of your screen or in the Object >Binding > Name tab on the right-hand side. The field in the error message above is called NumericField1[5].
Views
Replies
Total Likes
Ah! I see! Thank you SO much! it now works beautifully! you are a genius
Views
Replies
Total Likes
This post is really helpful. Due to certain reasons, I wanted to do this using Javascript. Is there a way to solve this using that? I have no idea how to approach that.
I would really appreciate if you could help me!!
MJ
Views
Replies
Total Likes
Views
Likes
Replies