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

can you use if and else in javascipt

mcapps
Registered: Jan 24 2008
Posts: 25

i just want to know if you can use if and else in the javascript for a button on a form

My Product Information:
Acrobat Standard 8.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Yes.

George Kaiser

mcapps
Registered: Jan 24 2008
Posts: 25
is there a limet to how many if else stamets you can have? cause i am having a proble were the javascript will run or skip the 1st part of the if but then when it hits the else it eneds the program. the 1st part will work no mater what is in there but it hits the else statment and stops
ChrisFreeman
Registered: May 6 2007
Posts: 19
I don't know if a specific hard limit exists, but I was able to create an "insane" test case which had 3,600 else if statements for a button mouse-up event. I say insane because using an extreme number of "else if" statements is considered very poor coding style. If you are using a large number of "else if" statements you might want to consider using a "case" statement instead.

Your description of unexpected "if else" execution seems to point to misplaced or missing curly braces "{" and "}".
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
With all the snow in Chicago, my snow globe crystal ball is not working. Without seeing the code and knowing which product you are creating your form in, it is not possible to diagnose the problem. You could try simpliying your code to one else statement and get that code to work and then add the next else statemt. Also open the JavaScirpt debugging console and see if there are any errors being reported. And as previously noted the "switch", "case", control statement might be a better solution.

The simplist form:

switch (myFieldValue) {

case "John" :
// code for John
break; // end John exit

case "Jack":
// code for Jack
break: // end Jack exit

case "Joe":
case "Joseph":
// code for Joe and Joseph
break; // end Joe and Joseph
default:
// all other options not selected
break; // end all others
} // end of switch

By replacing the value in the "switcht(value)" with a logical value of "true" the labels for the "case" can be complex statments that can evalute to 'true" or "false" allowing for very complex comparisons.

George Kaiser

mcapps
Registered: Jan 24 2008
Posts: 25
thanks but i found out what was worng some one was using a Else and not a else thanks