Copy link to clipboard
Copied
I found this article that talks about rename all duplicate field names.
for (var i=0;i<200;i++)
{
try{
var ts=this.getField("Name1."+i).textSize;
var tf=this.getField("Name1."+i).textFont;
var rct=this.getField("Name1."+i).rect;
var pg=this.getField("Name1."+i).page;
var f=this.addField("name."+i,"text",pg,rct);
f.textSize=ts;
f.textFont=tf;
}catch(e){break}
}
this.removeField("Name1");
I believed this script is for text box. I need to rename all my duplicate checkbox names. Do I sipmly changed the "text" to "checkbox" for checkbox field instead of text box field? I tried that and it didn't really work. I no longer can click on the checkbox once I ran this script. Any suggestion is much appreciated.
Use this code:
for(var i = 0; i< 61; i++){
if(this.getField("T Neej."+i)!= null){
var ts=this.getField("T Neej."+i).textSize;
var tf=this.getField("T Neej."+i).textFont;
var rct=this.getField("T Neej."+i).rect;
var pg=this.getField("T Neej."+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont="ZapfDingbats";
this.removeField("T Neej."+i);
}
}
Copy link to clipboard
Copied
Yes, that should do it. I would remove the try-catch clause, though, as it's hiding any errors you might get while running this code. Don't set the textFont property, though, if you create check-boxes. It might screw them up.
Copy link to clipboard
Copied
I could not get it to work. After I ran the code below, it did removed the existing checkbox and rename them; however, it's no longer a check box. I can no longer click the field to put a cross on it any more.
for (var i=0;i<200;i++)
{
var ts=this.getField("Name1."+i).textSize;
var tf=this.getField("Name1."+i).textFont;
var rct=this.getField("Name1."+i).rect;
var pg=this.getField("Name1."+i).page;
var f=this.addField("checkbox."+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont=tf;
}
this.removeField("Name1.");
Copy link to clipboard
Copied
Do not set the textFont of the check-boxes to anything else but the default value ("ZapfDingbats"). If you do that they won't work properly.
Copy link to clipboard
Copied
Same issue but with an error this time.
for(var i = 0; i< 200; i++){
var ts=this.getField("Name1."+i).textSize;
var rct=this.getField("Name1."+i).rect;
var pg=this.getField("Name1."+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
this.removeField("Name1.");
}
TypeError: this.getField(...) is null
2:Console:Exec
undefined
Copy link to clipboard
Copied
That means there isn't a field with the name you're specifying.
Copy link to clipboard
Copied
If I highlight this code, it does show the correct font name.
Copy link to clipboard
Copied
You should add a command to print out the value of i when the error happens. That way you could locate the missing field.
Copy link to clipboard
Copied
I also tried:
for(var i = 0; i< 200; i++){
var ts=this.getField("Name1."+i).textSize;
var tf=this.getField("T Neej."+i).textFont;
var rct=this.getField("Name1."+i).rect;
var pg=this.getField("Name1."+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont="ZapfDingbats";
this.removeField("Name1.");
}
and I got the same error:
TypeError: this.getField(...) is null
2:Console:Exec
undefined
Copy link to clipboard
Copied
Have you 200 checkboxes?
Copy link to clipboard
Copied
I don't know the exact checkboxes but it's like around 80-90 checkboxes.
Copy link to clipboard
Copied
But your counter runs to 200, so of course you're going to get an error...
Copy link to clipboard
Copied
You should check the field:
if (this.getField (" ... ") != null) {
...
}
Copy link to clipboard
Copied
So, here's my attempt to use "if" to check for not null.
for(var i = 0; i< 96; i++){
if(this.getField("Name1")!= null){
var ts=this.getField("Name1"+i).textSize;
var tf=this.getField("Name1"+i).textFont;
var rct=this.getField("Name1"+i).rect;
var pg=this.getField("Name1"+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont="ZapfDingbats";
this.removeField("Name1");
}
}
And the error is:
TypeError: this.getField(...) is null
3:Console:Exec
undefined
Copy link to clipboard
Copied
This code should show more than just one result of "10" but it's not.
Copy link to clipboard
Copied
Okay, this shows the correct number of checkboxes. But I'm still unable to get the "added" checkboxes to function like a checkbox. I'm unable to click on it.
Copy link to clipboard
Copied
What can you see when you look at the properties of the checkboxes?
Copy link to clipboard
Copied
The issue seems to be this line: var f=this.addField("checkBox."+i,"checkbox",pg,rct);
This line: this.removeField("Name1."); removes the current checkbox but the add line above failed to add additional checkboxes. When the code finished running, there is only one checkbox.0.
Copy link to clipboard
Copied
The name of the checkbox is "Name2".
Copy link to clipboard
Copied
I'm sorry, all the name of the checkboxes are just "Name". I renamed that particular checkbox for testing.
Copy link to clipboard
Copied
It's very difficult to help you because your descriptions continue to change. Unless you can share the actual file I can't help you any further with this. Maybe someone else can.
Copy link to clipboard
Copied
Attached is the test PDF I'm playing with. Below is the code I'm using.
for(var i = 0; i< 61; i++){
if(this.getField("T Neej.")!= null){
var ts=this.getField("T Neej."+i).textSize;
var tf=this.getField("T Neej."+i).textFont;
var rct=this.getField("T Neej."+i).rect;
var pg=this.getField("T Neej."+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont="ZapfDingbats";
this.removeField("T Neej.");
}
}
Copy link to clipboard
Copied
Use this code:
for(var i = 0; i< 61; i++){
if(this.getField("T Neej."+i)!= null){
var ts=this.getField("T Neej."+i).textSize;
var tf=this.getField("T Neej."+i).textFont;
var rct=this.getField("T Neej."+i).rect;
var pg=this.getField("T Neej."+i).page;
var f=this.addField("checkBox"+i,"checkbox",pg,rct);
f.textSize=ts;
f.textFont="ZapfDingbats";
this.removeField("T Neej."+i);
}
}
Copy link to clipboard
Copied
Thank you so much for the help! That solves the issue.
Copy link to clipboard
Copied
Is there a way to get the exact number of checkboxes based on the getField("Name1")?