These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

if / and statement (I know there must be a real easy answer...)

Torvik
Registered: Mar 14 2007
Posts: 25

I don't know much about Javascript, but it seems like this should be easy to do...

How do I make an "if" statement dependant on two variables.

i.e.

if (a == 1) && (b == 2){
3
}
else {
999
}

Thanks!
Alan

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
The entire statement to evaluated must be entirely within parentheses. Complex evaluations can be grouped within additional parenthseses to indicate the order of evaluation ar the logical relationship.

if ( (a == 1) & (b == 2) ) {
3
} else {
999
}// or

if (a == 1 && b == 2){
3
} else {
999
}

George Kaiser

Torvik
Registered: Mar 14 2007
Posts: 25
Thanks Geo
I never know where to enter scripting. Should it be under "calculate" or "Intialize" or what? (I usually put it under calculate.)

As well, this simple script just isn't working for me

if (a + b == 3) {
4
} else {
5
}

I put 1 in "a" and 2 in "b" but the box just remains 5. What am I doing wrong?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You have to use parenthesis to establish the computation statement before performing the comparison.

if ( (a + b) == 3) {
4
} else {
5
}

George Kaiser

Torvik
Registered: Mar 14 2007
Posts: 25
Right. Gotcha.
But (arghh!) it's still not working. The box still remains 5.

I double checked my references. I made this box mirror back the value of "a" and of "b" and it changes accordingly. I even made a box that was "a+b". the math says that the equation equals 3, but the if statement won't change...
What do you think?
Torvik
Registered: Mar 14 2007
Posts: 25
> If you do not want to write out the field and property, create a variable of the value:
>
> JavaScript:
>
> var a = fieldA.rawValue;
> var b = fieldB.rawValue;
> if ( (a + b) == 3)
> $.rawValue = 4;
> else $.rawValue = 5;
>
> //or
> var a = fieldA.rawValue;
> var b = fieldB.rawValue;
> (a + b) == 3 ? $.rawValue = 4 : $.rawValue = 5;
>
> FormCalc:
> var a = fieldA.rawValue;
> var b = fieldB.rawValue;
> if ( (a+b) == 3) then
> 4
> else 5
> endifOk. So I catch what you're saying. I altered it a little to make your examples work with my numeric fields, but when I alter it to fit with my 2 dropdown boxes, it won't make the connection. When "A" and "B" are numeric fields, everything is fine, but as soon as I change that to "DropDownList1" and "DropDownList2" it no longer works.

http://wildernessedge.com/dynam%20drops3.pdf

What is that about?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Have you tired the FormCalc example?

George Kaiser