Skip to main content
jasons35699793
Known Participant
April 5, 2019
Question

select an option or perform a calculation

  • April 5, 2019
  • 1 reply
  • 710 views

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

This topic has been closed for replies.

1 reply

jasons35699793
Known Participant
April 5, 2019

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

Thom Parker
Community Expert
Community Expert
April 5, 2019

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
jasons35699793
Known Participant
April 5, 2019

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?