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
};
};
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:
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