Skip to main content
Participating Frequently
Mar 4, 2025 1:34 AM UTC
Question

Combine multiple results in Javascript

In the javascript below I would like to combine multiple results. In this case Value2 - Value1 + Value4 - Value3

 

What I tied below returns an error:

SyntaxError illegal charater Line 9  value1) + (value4 - Value3)

 

// Get the values from the textboxes
var value1 = parseFloat(this.getField("RealEstate_Loan_1").value) || 0;
var value2 = parseFloat(this.getField("RealEstate_MarketValue_1").value) || 0;
var value3 = parseFloat(this.getField("RealEstate_Loan_2").value) || 0;
var value4 = parseFloat(this.getField("RealEstate_MarketValue_2").value) || 0;

// Perform the subtraction
var result = (value2 – value1) + (value4 – value3);

// Set the result in another field (e.g., ResultBox)
this.getField("RealEstate_NetValue_Total ").value = result.toFixed(2);

 

 

2 replies

try67
Community Expert
Community Expert
Mar 4, 2025 9:42 AM UTC

Also, there can't be a space at the end of the field name. So either the name you used in the code is wrong, or your field has an incorrect name. If you edit it in Acrobat at any point, it will be removed.

Translate
Nesa Nurani
Community Expert
Community Expert
Mar 4, 2025 5:38 AM UTC

The error "Illegal character" is likely due to the minus sign (–) you used in the subtraction operation. It appears to be a long dash instead of a regular minus (-).

Translate