Skip to main content
Participant
Mar 30, 2026 6:16 PM UTC
Question

Two if statements/ignore other conditions if variable value = 1

https://community.adobe.com/questions-9/conditional-equation-based-on-checkbox-1300826

 

So, my script has an issue where it'll do this formula even if the originals value is 1. Now, people shouldn't be putting 1 original and checking double-sided, but they are, and it's bothering me that the script is halving it when it shouldn't. I was thinking I want something like if var OG = 1, event.value = OG * CP, but putting that seems to screw up the rest of the formula. So then I was thinking, is it possible to have two if statements before the result so that I can make the other statements conditional on OG being more than 1, but I can't seem to find the right syntax for that either.

 

As it stands my formula is like this:

// Relevant Field References

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

var OTS = this.getField("Check Box1").valueAsString;

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

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

 

if(OTS !== "Off") 

event.value = Math.ceil(OG*CP/2);

else

if(TS !== "Off") 

event.value = Math.ceil(OG*CP/2);

else

event.value = OG*CP;

 

 

I'm open to other solutions if my idea how to fix it is too convoluted.

 

    3 replies

    Thom Parker
    Community Expert
    Community Expert
    Mar 30, 2026 8:11 PM UTC

    Here’s an article that will provide you with the answers.

    https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

     

    Translate
    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    Karl Heinz  Kremer
    Community Expert
    Community Expert
    Mar 30, 2026 6:33 PM UTC

    We don’t have enough information about what it is you want to do. One issue is that your variable and field names are not very descriptive, so I cannot make an educated guess about what you are trying to do. 

     

    If you always want to return OG*CP when you see that OG is set to 1, regardless of what OTS and TS are set to, then this should work:
     

    if ( OF == 1 ) { 
    event.value = OG*CP;
    }
    else if(OTS !== "Off") {
    event.value = Math.ceil(OG*CP/2);
    }
    else if(TS !== "Off") {
    event.value = Math.ceil(OG*CP/2);
    }
    else {
    event.value = OG*CP;
    }

    If this is not the case, we need a better description. 

     

    You may invest a little time to learn about JavaScript syntax, this will make it much easier to modify code you find. 

    Translate
    Participant
    Apr 2, 2026 3:45 PM UTC

    Ah yeah sorry. So OG is the number of originals, i.e. the number of pages a document has. CP is the number of copies to be made of the document. TS means the checkbox for two-sided (i.e. duplex copies requested). OTS is basically the same thing it's a holdover from the physical copy request paper.

     

    Anyway, thank you for putting up with my silly question! I felt like I was going in circles trying to research it on my own and the search engine was giving me conflicting info.

    Translate