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

"invalid break" error troubleshooting

mvivit
Registered: Nov 5 2008
Posts: 46
Answered

I have a JavaScript code that combines specific versions of forms based upon a set of user-specified state abbreviations. The validation function runs just fine, returning "false" if the type of compilation is not appropriate for one or more states. I want to alert the user that state(s) in the list is not appropriate, and stop the entire script following the user-clicked "OK". When I run the script from the console, it throws an "invalid break" error. Here is the offending set of code:

var aListOfStates = new Array();
	if (targetStates == "ALL") {
		aListOfStates = aAllStates;
		targetStates = aAllStates.join(",");
	}
	else {
		var noMatch = "";
		aListOfStates = targetStates.split(",");
 
		for (i = 0; i<aListOfStates.length; i++) {
			if (aAllStates.exists(aListOfStates[i]) == false) {
				noMatch += aListOfStates[i] + ",";
			}
		}
 
		if (noMatch != "") {
			app.alert("These states are not eligible for creating life application packets: " + noMatch);
			break;
 
		}
	}

All variables listed without the "var" are initialized earlier in the code.

(I apologize in advance if the formatting is poor: this is the first time I've added code to a message in this forum.)

In lieu of rewriting this, is there something I'm totally missing about using a break here?

Thanks for any suggestions and comments!

My Product Information:
Acrobat Pro 8.1.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
If you make all of the code into a function, you could simply use a return statement in place of your current break statement. Where you currently have the code, place a call to the function.

George
mvivit
Registered: Nov 5 2008
Posts: 46
Thanks, George! I'll give that a try.
mvivit
Registered: Nov 5 2008
Posts: 46
I ended up doing something a little different in preparation for another change that may happen. Thanks for the help, though - works just fine.