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

Shown/Hidden field no longer calculates when triggered by a radio button

Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

I have a simple subtraction calculation (A-B=C) that worked fine until I designated these fields as either shown/hidden based on the response to a radio button. If radio button 1 is clicked, the fields for A, B, and C are "shown". If any of the other radio buttons (button 2 or button 3) are clicked, A, B, and C are hidden. Once I added this script, the C field no longer calculates. Can anyone help?

TOPICS
Acrobat SDK and JavaScript

Views

195

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
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

There's no reason for the visibility of the fields to affect the calculation, so there is something else going on.  Have you ensured the calculation (script) is still there? Are A and B calculated values, or are they user entered? Has anything else changed on the form?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

A is user-entered, b is calculated based on the answer to A. I grouped the 3 fields with the same prefix "T1." so that when the first radio button is selected, these fields are shown. the calculation for B works.

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
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

Check the field calculation order. Make sure that C is calculated after B. The visibility of the fields has nothing to do with it, as mentioned.

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
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

yes, the order is correct.

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
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

Can you post the form so we can examine it?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

how do i post the form?

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
community guidelines
LEGEND ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

You need to use a filesharing site like dropbox or google drive and post a sharable link in the reply.

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
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

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
community guidelines
LEGEND ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

There are some problems with one or more of your scripts. Open the Acrobat JavaScript console and you will see the error messages.

You have some field names used in the "Simplified Field Name Notation" calculation that have special characters in their names. These characters cannot be present unless preceded by the JavaScript Escape Character, "\", that indicates the special character is to be treated as a character and not a separator or other special processing character.

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
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

Copy link to clipboard

Copied

thank you all, that did it. i didn't know about the JavaScript Escape Character.

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
community guidelines
Community Expert ,
Sep 23, 2018 Sep 23, 2018

Copy link to clipboard

Copied

LATEST

Another comment is that you are missing code to reset the value of the field in some calculations. For example, under "T1.HrsWk" you have this calculation script:

var a = this.getField("DAF_Score").value;

var b = this.getField("MAF").value;

var c = this.getField("Total_Eligible_HrsWk").value;

var d = this.getField("Tiers").value;

if(a>=25.25 && a<=45 && b=="Yes" && d=="Tier1") event.value = c;

else if (a>=25.25 && a<=45 && b=="No") event.value = "40";

But what if neither one of those conditions are met? In that case the field's value will remain unchanged because you're not applying any value to it. You should probably reset it to a blank string or even zero, by adding this to the end of your code:

else event.value = 0;

Or:

else event.value = "";

Also, I would recommend using valueAsString instead of value, and explicitly converting the values to numbers, where needed, like this:

var a = Number(this.getField("DAF_Score").valueAsString);

var b = Number(this.getField("MAF").valueAsString);

var c = this.getField("Total_Eligible_HrsWk").valueAsString;

var d = this.getField("Tiers").valueAsString;

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
community guidelines