A simple script that lets you calculate an amount based on a user’s input

It’s getting close to tax time here in Canada and I’m thinking about my retirement plan contributions. While looking at the Federal tax form online, I thought about how nice it would be if the form could calculate an amount based on my input. So I created a little script in LiveCycle Designer ES that calculates how much I can deduct based on my Registered Retirement Savings Plan (RRSP) contributions. Of course, the percentage I used for the calculation is purely fictional and the Canadian Government would never let me send in my own version of the form!

I used the response method to create the dialog box that contains the question and entry field. The following message box appears when I tab to the field.


Here is the calculated field:

To create the calculation in this example:
1. In Designer ES, drag a Decimal Field object onto the form design.
2. In the Field tab, select a pattern for the field. In this example I selected a predefined display pattern (num{($z,zz9.99)}).
3. In the Script Editor, select the Enter event, JavaScript language, and run the script at the Client.
4. Copy and paste the following script into the Script Editor.
var RRSPResponse = xfa.host.response("What is your total RRSP contribution for the year ?", "RRSP Contribution", "", false);
$.rawValue = RRSPResponse * 0.536;

5. Save the form as a PDF file.

Now you try it and have fun!

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 0.0/10 (0 votes cast)

Comments are closed.