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

NaN

Community Beginner ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

I'm trying to create an equation based on some fields in my form. I don't see where the error is, but the console is telling me my output is not a number. Any help would be appreciated.

 

var house = this.getField("SqFt");
var term = 120;
var margin = .0275;
var wh = 0;
var heat = 0;

if(house.value<="1500")house=1500;

if(this.getField("WaterHeater").value=="Electric Tank") wh=.03;
else
if(this.getField("WaterHeater").value=="Electric Tankless") wh=.05;

if(this.getField("Heat").value=="Combo") heat=.05;
else
if(this.getField("Heat").value=="Electric") heat=.10;

event.value = house.value*(.65 + wh + heat)*term.value*margin.value
NaN

TOPICS
Acrobat SDK and JavaScript

Views

234

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 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

In your last line you phrased your variables "term" and "margin" as  term.value and margin.value

 

Change that line to :

 

event.value = house.value*(.65 + wh + heat)*term*margin;

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
LEGEND ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Here's what I modify the script to:

 

// Get the value of the SqFt field, as a number
var house = +getField("SqFt").value;

if (house <= 1500) {
    house = 1500;
}

var term = 120;
var margin = 0.0275;
var wh = 0;
var heat = 0;

if (getField("WaterHeater").value == "Electric Tank") {
    wh = 0.03;
} else if (getField("WaterHeater").value == "Electric Tankless") {
    wh = 0.05;
}

if (getField("Heat").value == "Combo") {
    heat = 0.05;
} else if (getField("Heat").value == "Electric") {
    heat = 0.10;
}

// Set this field's value
event.value = house * (0.65 + wh + heat) * term * margin;

 

 

 

 

Also, this line:

 

if(house.value<="1500")house=1500;

 

Should be:

 

if (house.value <= 1500) house = 1500;

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
LEGEND ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Please ignore those last four lines of my previous response. They were accidentally included from my initial attempt.

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 Beginner ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

Why do you use the .value for the house variable, but not for the others? I suppose when I put the quotes around the 1500 I changed it from a number to a different type of value? I appreciate all the help with 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
LEGEND ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

LATEST

You need to use .value when the object (variable) comes from a form field. The form field has many properties (name, size, colour...) and you need the specific property called value. 

You must not use .value when the object (variable) is a simple number. 

It's a pain to keep this straight, and it's the sort of mistake I often make, but keep it straight we must. 

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