Skip to main content
2Charlie
Inspiring
December 23, 2021
解決済み

How to give all duplicate checkbox names a unique name?

  • December 23, 2021
  • 返信数 1.
  • 6165 ビュー

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.

このトピックへの返信は締め切られました。
解決に役立った回答 try67

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.");
    }
}

 


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

返信数 1

try67
Community Expert
Community Expert
December 23, 2021

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.

2Charlie
2Charlie作成者
Inspiring
January 3, 2022

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.");
try67
Community Expert
Community Expert
January 3, 2022

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.