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

error message for wrong page count...help?!

saj
Registered: Oct 15 2008
Posts: 52
Answered

I am not very savvy with scripting. But, I am trying to have a field that when the wrong page count is entered, it will error out in red. Page count needs to be in multiples of 4. For example, 4, 8, 16, etc.
I am using Acrobat 9 Pro on the mac.

I started with this:
_______________
var v1 = +event.value

if(v1 === 4) event.target.textColor = ["G",0];

else

{
event.target.textColor = ["RGB",1,0,0];
app.alert("Invalid Page Count");
}
_______________

But, as soon as I added another line--It errors out. So obviously I am not doing something right.
_______________

var v1 = +event.value

if(v1 === 4) event.target.textColor = ["G",0];
if(v1 === 8) event.target.textColor = ["G",0];

else

{
event.target.textColor = ["RGB",1,0,0];
app.alert("Invalid Page Count");
}

_______________

Can someone guide me in the right direction? Much appreciated.

My Product Information:
Acrobat Pro 9.1.2, Macintosh
revoxo
Registered: Jul 20 2009
Posts: 17
I'm no great javascript expert either but try this in the custom calculation of your field:


if (event.target.value % 4 == 0) {
event.target.textColor = ["G",0];
}
else {
event.target.textColor = ["RGB",1,0,0];
app.alert("Invalid Page Count")
}


This uses the "%" operator, properly called the modulus operator: it returns the remainder of an integer division, so for example 10 mod (or %) 4 = 2. By comparing the result to zero, you get rid of the need for any othe comparators.

I gleamed the above from a core javascript site and works correctly (for me at least).
Hope it helps.
saj
Registered: Oct 15 2008
Posts: 52
It worked!!! thank you!!