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

PDF form adding 2 values to the same field

Explorer ,
Nov 07, 2024 Nov 07, 2024

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?

TOPICS
PDF , PDF forms
925
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 07, 2024 Nov 07, 2024

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

View solution in original post

Translate
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 ,
Nov 07, 2024 Nov 07, 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;

Translate
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
Explorer ,
Nov 07, 2024 Nov 07, 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.

Translate
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 ,
Nov 07, 2024 Nov 07, 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.

Translate
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
Explorer ,
Nov 07, 2024 Nov 07, 2024

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.

Translate
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 ,
Nov 07, 2024 Nov 07, 2024

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

Translate
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
Explorer ,
Nov 07, 2024 Nov 07, 2024

That's absolutely perfect thanks very much for your help.

Translate
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 ,
Nov 07, 2024 Nov 07, 2024
LATEST

Sorry, I misunderstood what you meant. The code you got from @PDF Automation Station should do the trick.

Translate
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