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.
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.