Highlighted

script to trigger a form field calculation upon check mark selection

New Here ,
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!?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Macintosh, PDF forms, Windows

Views

2.2K

Likes

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

script to trigger a form field calculation upon check mark selection

New Here ,
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!?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Macintosh, PDF forms, Windows

Views

2.2K

Likes

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
Jul 06, 2017 0
Most Valuable Participant ,
Jul 06, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 06, 2017 0
New Here ,
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!

Likes

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
Reply
Loading...
Jul 06, 2017 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jul 06, 2017 0
New Here ,
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?

Likes

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
Reply
Loading...
Jul 06, 2017 0
Most Valuable Participant ,
Jul 06, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 06, 2017 0
New Here ,
Jul 06, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 06, 2017 0
New Here ,
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.

Likes

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
Reply
Loading...
Jul 07, 2017 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jul 07, 2017 0
New Here ,
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!

Likes

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
Reply
Loading...
Jul 10, 2017 0
New Here ,
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?

Likes

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
Reply
Loading...
Jul 17, 2017 0
Most Valuable Participant ,
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.)?

Likes

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
Reply
Loading...
Jul 17, 2017 0
New Here ,
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!

Likes

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
Reply
Loading...
Jul 18, 2017 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Jul 18, 2017 0
New Here ,
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!

Likes

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
Reply
Loading...
Jul 18, 2017 0
New Here ,
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!

Likes

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
Reply
Loading...
Jul 06, 2017 0
New Here ,
Oct 12, 2020

Copy link to clipboard

Copied

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 ; 

Likes

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
Reply
Loading...
Oct 12, 2020 0