Skip to main content
Jo_2013
Known Participant
January 23, 2018
Question

Indicate if checkbox ticked for multiple fields using getNthFieldName

  • January 23, 2018
  • 1 reply
  • 2713 views

I have created an Action script to place an X in text fields on page 1 if a corresponding check box is ticked which is located on  other pages of the document.

The pdf  file has multiple text fields on page 1 with the name of the text field beginning with C1.

In the rest of the document there are multiple check boxes with the name of the check box beginning with C1.

There are the same number of text fields and check boxes.

If the first check box  is ticked, then the first text box on page 1 should then have an X in the field.

If the second check box is ticked, then the second text box on page 1 should then have an X in the field etc.

I am  unsure how to capture the check box as a variable into the text field, if anyone can provide assistance that will be most appreciated.

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

var fname = this.getNthFieldName(i);

var f = this.getField(fname);

if (fname==null) continue;

if ( f.type == "checkbox" && fname.substring(0,2) === "C1")  {

console.println("checkbox " + this.getNthFieldName(i));

}

else if ( f.type == "textbox" && fname.substring(0,2) === "C1"){

console.println("textbox " + this.getNthFieldName(i));

var check = this.getField(??);

var cbStatus = (check.isBoxChecked(0));

if (cbStatus == 1) {

event.value = "X";

}

if (cbStatus == 0) {

event.value = "";

}

}

}

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
January 23, 2018

Use the name of the checkbox.

Jo_2013
Jo_2013Author
Known Participant
January 23, 2018

Thank you for your reply.  I will require further assistance please.

I need to place the check box name into if type == textbox section of the script, can you please advise how to get the name of the checkbox as a variant? This is what I have been unable to work out.   It is highlighted in blue.

try67
Community Expert
Community Expert
January 23, 2018

The variable fname contains the field name in your code.