3 Replies Latest reply on Sep 17, 2010 2:33 PM by JReneeC

# Syntax Error in Conditional Execution

I wrote the following script:

var CB3 = this.getField("CheckBox3").value;

var nSub2 = this.getField("Subtotal").value;

if (CB3 == "0") && (nSub2 <= 60)

event.value=15;

else if (CB3 == "0") && (nSub2 > 60)

event.value = nSub2 * 0.25;

Seems pretty simple to me, but I keep getting a syntax error on line 4, and when I enter it in the debugger, I get nothing.

I'm trying to set up my conditional execution that if the checkbox is checked and the subtotal is less than or equal to 60, then the result should be 15; however, if the checkbox is checked and the subtotal is more than 60, the result should be the 25% of the subtotal.

I'm sure it's probably going to be a very simple answer, but I'm a self learner of javascript, and I don't have all the tools down to figure out why it's not working.  So any help would be appreciated.

Thank you.

• ###### 1. Re: Syntax Error in Conditional Execution

Try this:

var CB3 = this.getField("CheckBox3").value;

var nSub2 = this.getField("Subtotal").value;

if ((CB3 == "0") && (nSub2 <= 60))

event.value=15;

else if ((CB3 == "0") && (nSub2 > 60))

event.value = nSub2 * 0.25;

But what do you want to happen if neither of those conditions are true?

• ###### 2. Re: Syntax Error in Conditional Execution

You have to put your conditional statement that resolves to a true or false value between parenthesis even if there are parenthesis within the statement. You have a compound test but there is now opening or closing parenthesis around the compound statements.

You could have

if ( CB3 == "0" & nSub2 <= 60 )

or

if (  (CB3 == "0") & (nSub2 <= 60)  )

or

if (  CB3 == "0" & (nSub2 <= 60)  )

or

if (  (CB3 == "0") & nSub2 <= 60  )

Not there is an opening "(" and closing ")" the encapsulates the entire statement.