Skip to main content
Participant
March 7, 2025
Answered

Conditional Equation based on checkbox

  • March 7, 2025
  • 1 reply
  • 588 views

Hello, I would like to create a conditional equation in Acrobat.

Something like:

If check box # is checked, perform this equation: (Number in field A * number in field B) / 2

And if is not checked, don't divide by 2.

I've tried cobbling together some scripts from different questions to get it to work, but it's just not going for it and I don't know what I'm doing wrong. I've never used JavaScript before and it's not being specific enough to tell me what exactly the problem is. It seems like it doesn't like my else statement, but when I remove it just to get it to go through it acts like there's still an error there EVEN WHEN THERE IS NO LINE 7 ANYMORE.

 

Baby's first JavaScript is as follows:

// Relevant Field References

    var TS = this.getField("Check Box5");

    var OG = Number(this.getField("Text3").value);

    var CP = Number(this.getField("Text13").value);

 

var PT = if TS.value = "On") event.value=OG*CP/2;

else event.value=OG*CP

 

 

 

Correct answer Nesa Nurani

Try this:

var TS = this.getField("Check Box5").valueAsString;
var OG = Number(this.getField("Text3").valueAsString);
var CP = Number(this.getField("Text13").valueAsString);

if(TS !== "Off") 
 event.value = OG*CP/2;
else 
 event.value = OG*CP;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
March 7, 2025

Try this:

var TS = this.getField("Check Box5").valueAsString;
var OG = Number(this.getField("Text3").valueAsString);
var CP = Number(this.getField("Text13").valueAsString);

if(TS !== "Off") 
 event.value = OG*CP/2;
else 
 event.value = OG*CP;
Participant
March 7, 2025

AAAA IT WORKS THANK YOU

 

one more thing I forgot about. How do I tell it to round up to the nearest whole number when the answer ends up being something like 2.5?

try67
Community Expert
Community Expert
March 7, 2025

Use Math.round() around the final value.

For example:

event.value = Math.round(event.value);