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

JavaScript Limit?

sjeppes
Registered: Dec 8 2011
Posts: 5
Answered

I have a problem. I am making an interactive form for my employer. I have a button at the bottom that when clicked it runs some JavaScript. After a point (it seems to very on how many lines so I wonder if it is character based) it gives a syntax error even when there is no error present, but it goes away if I delete anything beyond that point in the script. What can I do to make this work!?
 
Thanks.

My Product Information:
Acrobat Pro 10.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
What exact error message are you getting? It should also contain a line number at the beginning. Could you post that part of the code?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

sjeppes
Registered: Dec 8 2011
Posts: 5
The error message is:

SyntaxError: syntax error
52: at line 53

Here is the code(starting at line 52):

if (uHigh.isBoxChecked(0)) {
if (adl.value <= "5") {
rugScore.value = "RVA";
}else if (adl.value <= "10") {
rugScore.value = "RVB";
}else {
rugScore.value = "RVC";
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Well, in this bit there are a couple problems...
1. There's one closing curly bracket missing.
2. Using the math operators to compare strings is tricky. It compares one character at a time.
For example "2"<"10" will return false. However, this is not a syntax error.What type of field is uHigh?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

sjeppes
Registered: Dec 8 2011
Posts: 5
Ok so I am a dork and missed that closing bracket. I have a descending set of "if" statements and I fixed all the missing closing braces. But now i am getting a new error:

SyntaxError: missing } in compound statement
74: at line 75

here is my code (starting at line 74):

if (uHigh.isBoxChecked(0)) {
if (adl.value <= "5") {
rugScore.value = "RMA";
}else if (adl.value <= "10") {
rugScore.value = "RMB";
}else {
rugScore.value = "RMC";
}
}

and uHigh is a check box.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Now this part is solved, and there's another problem somewhere else (line 74).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

sjeppes
Registered: Dec 8 2011
Posts: 5
Ok. But I have check all my bracers ( "{" and "}" ) and all of them are there. So what I am wondering is if there is a limit to the amount of java I can put in a button using a mouse up run java script action?

I am wondering this because I have put my code into a syntax checker and it came back clean (after a few more fixes) but I am getting a syntax error at line 79 in acrobat only.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
I'm guessing there is, but I can hardly imagine you reached it. It would be in the tens of thousands, if at all.
The problem must lay elsewhere. If you wish, send me the file by email and I'll have a look at it.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
Accepted Answer
There is a limit, but it is not caused by Acrobat JavaScript or the Acrobat JavaScript concept. The limit is caused by the text editor Acrobat is using for JavaScripts. This text editor has a limit of 32k characters (or is it 64 k ?). But that can easily be overcome by using an external text editor (such as TextWrangler (the free "little brother" of BBEdit) on Mac, or NoteTab on Windows).

Now, as you are creating somewhat nested code, I would strongly suggest to develop that in a programmer's text editor which has parentheses balancing and and code coloring. The above mentioned editors do have that. This will help you getting your parentheses (and quotes) sorted out.

One more thing, and take it from an old-time Acrobat JavaScript developer: An error is rarely in the line Acrobat claims that it is. In fact, the line number shown is where the JavaScript interpreter noticed that there is an error. The cause may be on that line, or anywhere earlier.

Hope this can help.

Max Wyss.

sjeppes
Registered: Dec 8 2011
Posts: 5
Thanks Max.

I decided to try using Deramweaver as my external editor. Worked like a charm then. Thanks.
mbensch
Registered: Dec 12 2011
Posts: 2
I hope this answer the problem I was having in my form.
I have a bunch of fields (300+) but as I was adding in basic total functionality and some more custom formulas. I was noticing that instead of summing the total field. it was starting to display as if it was adding text.
Example:
[1] + [ ] + [2] + [3] = [6]

after a while:
[1] + [ ] + [2] + [3] = [123]

I am just hoping it is an editor problem like sjeppes.

I will be doing some stuff in LiveCycle coming up and I was wondering if there is the same limitation or if it will be fine to use the built in script editor?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
mbensch,

Your problem is likely unrelated to what's been discussed and is much more likely due to the fact that when you get the value of an empty field, the result is a zero length string, which then results in string concatenation when you use the + operator to add the values together. The fix is to explicitly convert each field value to a number, assuming you're dealing with numeric fields. The unary + operator will do this and it will convert zero length strings to the number 0. So you code could look something like:

// Custom calculate script for text field

// Get the field values as numbers
var v1 = +getField("text1").value;
var v2 = +getField("text2").value;
var v3 = +getField("text3").value;

// Sum the field values and set this field value to the sum
event.value = v1 + v2 + v3;