Skip to main content
May 4, 2016
Question

custom calculation script to add two fields and show the result in a third field only if user enters data into one or both of the 1st two fields

  • May 4, 2016
  • 1 reply
  • 723 views

I'm trying to write a script that will calculate the sum of two field if there is a value entered into one or both of the fields. So far, the custom calculation in the third field looks like this:

    var c2 = this.getField(“Cargo WeightRow2”).value;

    var t2 = this.getField(“Tare WeightRow2”).value;

    if(c2 == “ ”) && (t2 == “ ”)

    event.value = c2 + t2;

    else if(c2 == “ ”) || (t2 == “ ”)

    event.value = c2 + t2;

    else if(c2 = “ ”) && (t2 = “ ”)

However, I want the user to be able to manually enter a value into the third field if both of the other fields are empty. Please help.

This topic has been closed for replies.

1 reply

Inspiring
May 4, 2016

Have you tried your code in a form?

Do you get any errors displaying as you save the code or test the form?

You need to use a plain text editor and not a word processor with smart quotation marks.

MDN has the JavaScript Reference online for free and Adobe does the same for the Acrobat JavaScript Reference.