Skip to main content
Colin Darby
Participating Frequently
November 7, 2024
Answered

PDF form adding 2 values to the same field

  • November 7, 2024
  • 1 reply
  • 908 views

I have a form with a tick box that adds a value to a single field when ticked, and zeroes it when unticked.

 

The custom calculation script in this single field is:

event.value = this.getField("Tick domestic electrical").value == "Off" ? 0 : 516;

 

This works OK.

 

However I want a second tick box that adds the same value to that single field as well.

But I want it to add that same value, only if the other box is unticked and vice versa.

 

How can I get this to work?

This topic has been closed for replies.
Correct answer PDF Automation Station

Yes you're right sorry it's case sensitive.

 

The fields are now inputting, but when I tick the second box it adds the first tick box value to the second.

 

I don't want that, it only needs to add one instance of the value.

 

If the second box is ticked also it doesn't add a further value to the field.


if(this.getField("Tick domestic electrical").value == "Off" &&
this.getField("Tick domestic electrical2").value == "Off")
{event.value=0}else{event.value=516}

1 reply

try67
Community Expert
Community Expert
November 7, 2024

You can use something like this:

 

var v1 = this.getField("Tick domestic electrical").value == "Off" ? 0 : 516;
var v2 = this.getField("Tick domestic electrical2").value == "Off" ? 0 : 516;
event.value = v1+v2;

Colin Darby
Participating Frequently
November 7, 2024

Thanks, I removed the previous script and added this one, now the field stays at zero when I click or unclick the tick box.

try67
Community Expert
Community Expert
November 7, 2024

Did you make sure to enter the correct field name in the second line of code? I just added "2" at the end of the one you used, since you didn't specify what it should be in your original post.