Skip to main content
Thomas Knight
Known Participant
July 6, 2017
Answered

script to trigger a form field calculation upon check mark selection

  • July 6, 2017
  • 3 replies
  • 6171 views

Upon selecting a checkbox I would like to have a form field auto fill based on a multiplication of two other form fields.

Is this possible? Can someone provide the appropriate Java Script please!?

This topic has been closed for replies.
Correct answer try67

Ok, I haven't been able to figure this out and need more assistance please.

At this point I have found the following script which I have placed in the "Custom Calculation" area of the field.

event.value=this.getField("TotalLinearFt").value*145;

As of now this script preforms the calculation and populates the field.

I think you understand this already but to reiterate, I would like to have the field blank when a check box or radio button is unchecked and populated when it is checked or selected.

I am thinking I need another piece of script that links the check box to the code and it's respective field?

Net/net, currently upon selecting the check box the field doesn't populate with the calculation automatically. I don't know how to link the selection of the Check Box or Radio Button to trigger the action of filling the field with the calculation.


No, that's not what you said before... I asked: Is the calculation dependent on the value of the check-mark? If so, how?

You answered that no.... Now you're saying that the value of the text field is dependent on the value of the check-box.

To do that you should use this code:

if (this.getField("Checkbox1").value=="Off") event.value = "";

else event.value=this.getField("TotalLinearFt").value*145;

Change the name of the field in the first line of code to match the actual one, of course.

3 replies

Participant
October 12, 2020

I am trying to use this script and it keeps giving me the error "SyntaxError: missing ; before statement 1: at line 2 - not sure where to put the ; 

Thomas Knight
Known Participant
July 6, 2017

No, basically I have a sales rep filling out a form. The form has a number of check boxes. Each check box is associated with a different product cost per sq foot.

So ideally here's the UX:

1) the salesman fills in total sq footage in Field 1.

2) He selects the appropriate product check box which triggers a multiplication of Sq Footage specified in Field 1 x Cost per Sq Foot the resulting calculation populates the final form field, Field 2.

Hope this makes sense!

try67
Community Expert
Community Expert
July 6, 2017

Is the calculation dependent on the value of the check-mark? If so, how?

Thomas Knight
Known Participant
July 6, 2017

No, basically I have a sales rep filling out a form. The form has a number of check boxes. Each check box is associated with a different product cost per sq foot.

So ideally here's the UX:

1) the salesman fills in total sq footage in Field 1.

2) He selects the appropriate product check box which triggers a multiplication of Sq Footage specified in Field 1 x Cost per Sq Foot the resulting calculation populates the final form field, Field 2.

Hope this makes sense!

try67
Community Expert
Community Expert
July 6, 2017

You just need to set up the calculation under Field 2, then. You can use the built-in Product option under the Calculate tab.

The calculation gets executed each time the value of any field in the file changes, including when ticking/un-ticking a check-box.