Skip to main content
Participating Frequently
March 4, 2025
Question

Combine multiple results in Javascript

  • March 4, 2025
  • 2 replies
  • 206 views

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
March 4, 2025

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.

Nesa Nurani
Community Expert
Community Expert
March 4, 2025

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 (-).