Skip to main content
Participant
September 20, 2023
Answered

How to populate interactive fields sequentially based on the first number input into a field

  • September 20, 2023
  • 3 replies
  • 1197 views

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.

This topic has been closed for replies.
Correct answer JR Boulay

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

 

 

3 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
September 21, 2023

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

 

 

Acrobate du PDF, InDesigner et Photoshopographe
Participant
September 22, 2023

This has been very helpful. Thank you for your time.

JR Boulay
Community Expert
Community Expert
September 20, 2023

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

 

Acrobate du PDF, InDesigner et Photoshopographe
Participant
September 21, 2023

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?

Participant
September 20, 2023

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.