I am trying to creat a simple javascript calculation in LiveCycle and I am completly lost.
I have 3 numeric fields (A1, A2, A3) and one calculated field. When users input numbers into any of the first three fields, I would like the calculated field ("cost") to populate automatically. I have tried to piece together the javascript from reading other posts, but I cannot get my form to process the calculation. (The field is left blank.) Any help would be greatly appreciated.
Here is the calculation I am trying to make:
(A1/A2) * A3
Solved! Go to Solution.
Views
Replies
Total Likes
On the calculate event of the field that will hold the result of this calculation you woudl add this line of javascript code:
this.rawValue = (A1.rawValue/A2.rawValue) * A3.rawValue;
Hope that helps
Paul
Views
Replies
Total Likes
On the calculate event of the field that will hold the result of this calculation you woudl add this line of javascript code:
this.rawValue = (A1.rawValue/A2.rawValue) * A3.rawValue;
Hope that helps
Paul
Views
Replies
Total Likes
Yes, thank you, the calculation is working!
But I am having an additional problem. The calculation shows up on the form when the user tabs to the calculated field. However, it shows with an infinite number of decimal places. When the user tabs or clicks off the field, it does run the validation pattern. (I want the number to display as currency, with two decimal places.) But is there any way to round the number as it calculates it, or prevent it from initally showing all those decimal places?
Also, although I intially set the validation pattern for my numeric field, now that I have set the Value type to Calculated - Read only, I can no longer set the validation pattern (it is grayed out).
???
Thank you
Views
Replies
Total Likes
Make your field "User Entered - Optional". This will allow you to modify the Validation Patterns. Set the disply pattern to num.currency{}. Now change filed back to "Calculated ReadOnly" and the pattern will be applied to your result.
Paul
Views
Replies
Total Likes
It still doesn't display correctly until after the user clicks out of the field?
Views
Replies
Total Likes
Which field .....the calculated field?
Paul
Views
Replies
Total Likes
Correct - the calculated field.
Views
Replies
Total Likes
But if the field is set as Calculated ReadOnly how are you entering the field?
Once you make a change to A1, A2 or A3 the calculation wil fire automagically and the formatting will be applied to your result and put into your field.
Unless I am missing something.
Paul
Views
Replies
Total Likes
I'm not actually entering in the field - when I tab out of the last field, A3, the cursor lands in the calculated field, and highlights the calculated amount, with extraneous decimal places. I cannot edit it. When I then tab out of the field, it displays correctly. It's just when the cursor lands on that field initially. I'm not sure a user would tab out of the field, so I would prefer it not have the extra decimal places.
Thanks
Views
Replies
Total Likes
Under the Object palette/ Value Tab what is the Type Dropdown set to (my guess is Calculated Read Only). Try changing it to readOnly and try again.
Paul
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies