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

select an option or perform a calculation

New Here ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

I have a form that has spots for first floor and second floor elevations for a house. Unfortunately not all of the houses have a second floor. Is there a way that I can prompt the user to ask if there is a second floor and if not have it place N/A in the box and if so have it add 9 feet to the first floor. The form is set up so everything is calculated off of the Highest adjacent grade and split between different boxes for the integer and decimal.

the code for the first floor calculation is 

var num = this.getField("HAG").value + this.getField("HAGdec").value/10 + 2;

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("FirstFloordec").value = aNum[1];

I'm assuming second floor would be

var num = this.getField("HAG").value + this.getField("HAGdec").value/10 + 11;

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("SecondFloordec").value = aNum[1];

plus whatever is necessary for allowing the user to choose N/A

TOPICS
Acrobat SDK and JavaScript

Views

321

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

Here is what I have so far.

var upstairs = app.alert("Is there a second floor?", 2,2);

if (upstairs == 4){var num = this.getField("HAG").value + this.getField("HAGdec").value/10 + 11;

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("SecondFloordec").value = aNum[1];}else[{event.value = "N/A";

}

a box appears prompting for yes or no but I am not using the input correctly it seems

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

What is or isn't happening?

So it is generally a bad idea to use a popup box in a calculation script. Calculations are called any time any field value is changed.

It would be better to have a checkbox for "Has a 2nd Floor", then set the field values in the calculation based on the checkbox.

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

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

The form is for an elevation certificate for a city or county assessor unfortunately I can't add much too it that is why I'm trying to find a way to perform the check without adding something to the form that can't be shown when the form is printed. Is there a way to add a check box with the question, then perform the calculation and not have the check box or the question appear on the form when it is printed?

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

Yes, All form fields have a visibility property on the General Tab of the Properties dialog. Set it to "Visible but doesn't print"

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

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

Ok can you point me in the write direction to rewrite my calculation to use the check box. A link to something similar would be great. Am I in the vicinity here

(function(){

if(this.getfield("upstairs").value==="Yes"){

var num = this.getField("HAG").value + this.getField("HAGdec").value/10 + 11;

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("SecondFloordec").value = aNum[1];}else{

event.value = "N/A";

}}

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

You're code looks about right. Why is it in a function?

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

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

I was looking up other code that was similar to what I am wanting to see if that would work. Here is the code outside of a function

if(this.getfield("upstairs").value === "Yes"){

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("SecondFloordec").value = aNum[1];} else{

event.value = "N/A";

}

TypeError: this.getfield is not a function

1:Field:Calculate

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

It's getField, not getfield. JS is case-sensitive.

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

LATEST

Thank you I now have it doing the calculation with the check box but I want it to not enter anything in 2ndFloordec if the box is checked is there a way to do that?

if(this.getField("upstairs").value==="Yes"){

var num = this.getField("HAG").value + this.getField("HAGdec").value/10 + 11;

var strNum = util.printf("%0.1f",num);

var aNum = strNum.split(".");

event.value = aNum[0];

this.getField("2ndFloordec").value = aNum[1];}else{

event.value = "N/A";

}

I got it thank you for the help just needed to add

("2ndFloordec").value = (" ");

before 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