Skip to main content
MaxRosenthal
Participating Frequently
August 5, 2026
Answered

missing ) after condition

  • August 5, 2026
  • 7 replies
  • 38 views

Hi, I’ve been trying to teach myself basic javascript to automate some PDFs at work and I’m stuck on a formatting issue that is not obvious to me at the moment. The code in the script editor is as:

var WMS = this.getField("Water Meter Size").valueAsString;

if (WMS==="") {
event.rc=true;
} else if (WMS==="1" Line 5/8" Meter") {
event.value=75;
} else if (WMS==="1" Line and Meter") {
event.value=90;
} else if (WMS==="1.5" Line and Meter") {
event.value=125;
} else if (WMS==="2" Line and Meter") {
event.value=150;
} else {
event.value="";
}

Water Meter Size is a dropdown field with set strings.

When I try to close the window with ‘OK’ I’m getting the error ‘SyntaxError: missing ) after condition 5: at line 6’. It’s not clear to me where the closing operator is intended to be.

    Correct answer Amal Jaiswal

    Hi @MaxRosenthal 

    Hope you are doing well, and thanks for reaching out.

    The problem is the double quote marks you're using for inches (") inside your string values. JavaScript uses double quotes to mark where a string starts and ends, so as soon as it hits the " right after 1, it thinks your string is already finished, and everything after that becomes invalid code. That's what's triggering the "missing ) after condition" error.

    The fix is to either escape the internal quotes with a backslash, or simpler, wrap those strings in single quotes instead, since the inch marks won't conflict with single quotes: One thing worth double-checking once this runs without erroring: make sure these strings match your dropdown's export values exactly, spacing included, and the exact character used for the inch mark. If the dropdown was built with a curly/smart quote (” instead of a straight "), a straight-quote comparison here won't match even though they look identical on screen.

    Please check Adobe's official JavaScript API doc for Acrobat: Acrobat JavaScript API Reference for more information.

    Note: I'm not a JavaScript expert myself, this is based on my research into how Acrobat's scripting engine handles quotes, please give it a try and let me know if it works.

    ~Amal



    7 replies

    Amal Jaiswal
    Community Manager
    Amal JaiswalCommunity ManagerCorrect answer
    Community Manager
    August 5, 2026

    Hi @MaxRosenthal 

    Hope you are doing well, and thanks for reaching out.

    The problem is the double quote marks you're using for inches (") inside your string values. JavaScript uses double quotes to mark where a string starts and ends, so as soon as it hits the " right after 1, it thinks your string is already finished, and everything after that becomes invalid code. That's what's triggering the "missing ) after condition" error.

    The fix is to either escape the internal quotes with a backslash, or simpler, wrap those strings in single quotes instead, since the inch marks won't conflict with single quotes: One thing worth double-checking once this runs without erroring: make sure these strings match your dropdown's export values exactly, spacing included, and the exact character used for the inch mark. If the dropdown was built with a curly/smart quote (” instead of a straight "), a straight-quote comparison here won't match even though they look identical on screen.

    Please check Adobe's official JavaScript API doc for Acrobat: Acrobat JavaScript API Reference for more information.

    Note: I'm not a JavaScript expert myself, this is based on my research into how Acrobat's scripting engine handles quotes, please give it a try and let me know if it works.

    ~Amal



    MaxRosenthal
    Participating Frequently
    August 5, 2026

    Thank you. That fixed the syntax error, but now I have a dropdown export or var import issue I’m trying to figure out.

    I changed the export values in the dropdown items to simple numbers like 5/8, 1, 1.5, 2 and set those values in my elseif statements but there are no event values returning from this custom script.

    Amal Jaiswal
    Community Manager
    Community Manager
    August 5, 2026

    Hi MaxRosenthal,

    Great, glad to hear that cleared up the syntax error.

    This next one is very likely down to how the numbers are written in your elseif comparisons now. WMS comes from valueAsString, which always returns text, even if your dropdown export values are simple numbers like "5/8", "1", "1.5", "2", Acrobat still treats them as strings, not actual numeric values.

    If your updated script writes those comparisons without quotes, something like:
    else if (WMS === 5/8) {

    that's likely the problem, for two reasons:

    1. 5/8 without quotes gets evaluated as division first — JavaScript reads it as the number 0.625, not the text "5/8".
    2. Even a whole number like WMS === 1 compares a string ("1") to an actual number (1). The === operator requires both type and value to match, so a string and a number will never be equal this way, no matter what they "look like."

    The fix is to wrap every comparison value in quotes, so string is compared to string:

    Something like

    var WMS = this.getField("Water Meter Size").valueAsString;

    if (WMS === "") {
        event.rc = true;
    } else if (WMS === "5/8") {
        event.value = 75;
    } else if (WMS === "1") {
        event.value = 90;
    } else if (WMS === "1.5") {
        event.value = 125;
    } else if (WMS === "2") {
        event.value = 150;
    } else {
        event.value = "";
    }

    One more thing, since you said no event values are returning at all, even for values that should clearly match: this kind of script needs to live in the Calculate tab ("Custom calculation script") of the field that's supposed to display the result, not in the Validate or Format tab of the "Water Meter Size" dropdown itself. If it's on the wrong tab or attached to the wrong field, event.value won't show up anywhere, even with perfectly correct logic.

     

    Please note that, I'm not a JavaScript expert, this is based on the most common causes for this exact symptom
     

    ~Amal