Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
9

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

Community Beginner ,
Sep 20, 2023 Sep 20, 2023

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.

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
949
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Sep 20, 2023 Sep 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 Photoshoptographe

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2023 Sep 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 Photoshoptographe

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 20, 2023 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2023 Sep 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 Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 21, 2023 Sep 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2023 Sep 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 Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 22, 2023 Sep 22, 2023
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines