Skip to main content
May 12, 2016
Question

Custom Javascript: Defining target cell name based on host cell name

  • May 12, 2016
  • 1 reply
  • 629 views

Hi,

I want to create a form for recording test results of large batches, so I have 400+ fields that I want to apply this percentage calculation to, the calculation will always be performed based on the values in the cells 1 & 2 positions to the left. So to avoid having to edit each of these fields manually and specifying the target fields name, I hope to be able to at the very least just have to paste in a custom script to each cell.

Given the number of fields adobe has created the form from a grid saved in the PDF. Is it possible to script the variable based on the cell name and apply it to the target names, see the example below?

Current script (I know the maths is currently wrong):

Cell name that holds this is Row1

var a = this.getField("FinishRow1"); var b = this.getField("StartRow1"); event.value = (a.value + b.value) * 0.0010;

Ps) Of course if I'm fundamentally approaching this in the wrong way any guidance would be appreciated.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 12, 2016

What is the name of the target field, in the example you provided above?

May 12, 2016

Thanks for help,

Name of host field is: Row1

target field 1 is: StartRow1

target field 2 is: FinishRow1

hence I'm hoping to be able to:

var a = "start"+host field name

var b="finish"+host field name

var c= var a.value

var d = var b.value

event.value = var c.value / var d.value

May 12, 2016

I can extract (display) the individual values from the target cells with this code, but I don't seem to be able to perform the calculation with those values and I don't understand why.

Edit: The field displays NaN (Not a Number) I must be nearly there any assistance appreciated.

var S1 = event.target.name;

var S2 = "Finish".concat(S1);

art"+S1;

var S4 = S2+S1;

var S5 = S3+S1;

event.value = this.getField(S3).value; //Displays the numerical value stored in the appropriate cell for S2 or S3 as selected

//var a = this.getField(S2).value;

//var b = this.getField(S3).value;

//event.value = (a.value / b.value);