• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

script to trigger a form field calculation upon check mark selection

New Here ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

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!?

TOPICS
PDF forms

Views

4.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 07, 2017 Jul 07, 2017

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.

Votes

Translate

Translate
Community Expert ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

So, to interpret your note: I need an additional field to perform the calculation? (Which I've done)...  but how do I associate that result to the action of selecting the checkbox and populating Field 2 with the calculation?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

You don't need to associate them. It will happen automatically.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

It's not working. I'll keep trying. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2017 Jul 07, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2017 Jul 07, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Ok this script works great! Thank you very much!

Now I'm having one more issue that perplexes me – now that the checkboxes linked to the calculation, the 8 fields that contain the calculations need to be subtotaled. Currently I have a subtotal field that adds the 8 fields up. But something is odd, when a product checkbox is selected it should populate the subtotal field but doesn't until it is unchecked. One other problem, the unchecked field calc remains in the subtotal. I am guessing I need a script for the subtotal field. One that tallies one or more selected calc fields?

Can you provide some additional assistance please?

Uhhhhggggg!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2017 Jul 17, 2017

Copy link to clipboard

Copied

I sent you this reply a week or so ago... hoping you missed it.

Ok this script works great! Thank you very much!

Now I'm having one more issue that perplexes me – now that the checkboxes linked to the calculation, the 8 fields that contain the calculations need to be subtotaled. Currently I have a subtotal field that adds the 8 fields up. But something is odd, when a product checkbox is selected it should populate the subtotal field but doesn't until it is unchecked. One other problem, the unchecked field calc remains in the subtotal. I am guessing I need a script for the subtotal field. One that tallies one or more selected calc fields?

Can you provide some additional assistance please?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2017 Jul 17, 2017

Copy link to clipboard

Copied

It should work as is, since you're changing the value of the fields, not just showing/hiding them... Can you share the file (via Dropbox, Google Drive, Adobe Cloud, etc.)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2017 Jul 18, 2017

Copy link to clipboard

Copied

Sure I can share the file. I will send you a link.

thanks for all of your help on this!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2017 Jul 18, 2017

Copy link to clipboard

Copied

I should have guessed it... It's a field calculation order issue. Go to Form Edit mode, and then to Other Tasks (or More in Acrobat DC), Set Field Calculation Order. Make sure that the total fields are calculated after the fields they are summing up.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2017 Jul 18, 2017

Copy link to clipboard

Copied

Ok. I remember reading a bit about that. I should be able to sort it out.

Thanks for all of your help.

Once again I appreciate it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2020 Oct 12, 2020

Copy link to clipboard

Copied

LATEST

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 ; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines