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

Count Checkboxes on form and Change Border Color

djjones
Registered: Jul 24 2007
Posts: 14

I'm working with a fill in pdf form that simply changes the boarder color to transparent for every text field that has a value in it. I need to do the same thing for the checkboxes but it's not working. Can someone please help.

for ( var i = 0; i < this.numFields; i++)
{
var fname = this.getNthFieldName(i);

var f = this.getField(fname);
if (!(f.valueAsString == ''))
{
color.transparent = new Array("T")
f.strokeColor = color.transparent
};
};

for ( var i = 0; i < this.numFields; i++)
{
var fname = this.getNthFieldName(i);

var f = this.getField(fname);
if ( fname.type = "checkbox");

if (!(f.valueAsString == ''))
{
color.transparent = new Array("T")
f.strokeColor = color.transparent
};
};

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are number of issue with the code.

First, the first loop will affect all fields on the form, not just text fields. So you only need one loop, then inside the loop test for the field type before preceeding with the test.

Second, in the loop that tests the checkboxes, "fname" is a string, but the code needs to test "f", which is the field Object.

Third, Checkboxes have a value that is either "Off" or the export value. They are never empty. So, do you want the checkbox border to be transparent if it is unchecked?

Fourth, you cannot end an if statement with a semicolon, this is a sytax error and would have been reported in the console window. The console window is massively useful. See the links in my sigature block below.

Fifth, Too many semicolons. These are used to terminate a statement. Code blocked off with braces do not need to be terminated. Also, for neatness you shouldn't mix quote types, use either single or double quotes, but stick with one.

Here's a rewrite of your script:
for ( var i = 0; i < this.numFields; i++){var cFldNm = this.getNthFieldName(i); var oFld = this.getField(cFldNm);if ( oFld.type = "text"){if (oFld.valueAsString != "")oFld.strokeColor = ["T"];}else if ( oFld.type = "checkbox"){if (oFld.valueAsString != "Off"))oFld.strokeColor = ["T"];}}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

djjones
Registered: Jul 24 2007
Posts: 14
Hey thanks!

I understand the point about the loop. I changed my script but now none of the boxes are changing to transparent where as the at least the text fields were changing before.