Copy link to clipboard
Copied
I am trying to create an interactive PDF that will auto populate the fields based on the first number input into field 1. If the user put in number 001 then all other boses will auto poulate with the logical next number. It also need to be dynamic enough to know the next sequential numbers if the user inputs number 145 in the first field.
Copy link to clipboard
Copied
See attachment.
if (event.value != event.target.defaultValue) {
var nb = event.value;
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = Number(nb) + i;
}
}
else {
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = this.getField("Text." + i).defaultValue;
}
}
Copy link to clipboard
Copied
Try this one:
(If event.value is not a number nothing happen)
if (event.value != event.target.defaultValue && !isNaN(event.value)) {
var nc = event.value;
var nb;
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
nb = Number(nc) + i;
if (nb < 10) {nb = "000" + nb.toString();}
else if (nb >= 10 && nb <100) {nb = "00" + nb.toString();}
else if (nb >= 100 && nb <1000) {nb = "0" + nb.toString();}
this.getField("Text." + i).value = nb;
}
}
else {
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = this.getField("Text." + i).defaultValue;
}
}
Copy link to clipboard
Copied
upon reading about Javascript calculation I think the calculation needs to be incrementing. but i cannot figure out how to write this for interactive PDF.
Copy link to clipboard
Copied
See attachment.
if (event.value != event.target.defaultValue) {
var nb = event.value;
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = Number(nb) + i;
}
}
else {
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = this.getField("Text." + i).defaultValue;
}
}
Copy link to clipboard
Copied
Thank you very much for this. IIt is working as intended. Now my next question is, is it possible to get this to work when i use 0001 as my first number? the following numbers only incriment as single digits 2, 3, 4 and so on. I would like it to incriment 0002, 0003 and so on. If at all possible?
Copy link to clipboard
Copied
Try this one:
(If event.value is not a number nothing happen)
if (event.value != event.target.defaultValue && !isNaN(event.value)) {
var nc = event.value;
var nb;
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
nb = Number(nc) + i;
if (nb < 10) {nb = "000" + nb.toString();}
else if (nb >= 10 && nb <100) {nb = "00" + nb.toString();}
else if (nb >= 100 && nb <1000) {nb = "0" + nb.toString();}
this.getField("Text." + i).value = nb;
}
}
else {
for (var i=1; i<21; i++) { // start at text.1 and stop at text.20
this.getField("Text." + i).value = this.getField("Text." + i).defaultValue;
}
}
Copy link to clipboard
Copied
This has been very helpful. Thank you for your time.