Skip to main content
Known Participant
July 16, 2021
Answered

Field value reverts after other field has a changed value

  • July 16, 2021
  • 1 reply
  • 838 views

I wonder if it is possible, and then how, to make 2 fields that are auto-filled on the same page and user can edit the values, after values are edited in the field they keep the way it was fixed, and in case 2nd is edited, the first field's values would not revert to the initial values.

 

I use the script for both fields:

event.target.value = this.getField("Textfield-3").valueAsString + " " + this.getField("Textfield-4").valueAsString + ", " + this.getField("Textfield-5").valueAsString + ", " + this.getField("Textfield-6").valueAsString + ", " + this.getField("Textfield-9").valueAsString

This topic has been closed for replies.
Correct answer try67

Sure. Try this:

 

var fieldNames = ["Textfield-3", "Textfield-4", "Textfield-5", "Textfield-6", "Textfield-9"];
if (event.source && fieldNames.indexOf(event.source.name)!=-1) {
	event.value = this.getField("Textfield-3").valueAsString + " " + this.getField("Textfield-4").valueAsString + ", " + this.getField("Textfield-5").valueAsString + ", " + this.getField("Textfield-6").valueAsString + ", " + this.getField("Textfield-9").valueAsString;
}

1 reply

try67
Community Expert
Community Expert
July 17, 2021

You need to add a condition to your code that looks at the field that triggered the event (via event.source.name) and only if it's one of the fields in this list, then update the value automatically.

Beata5CBFAuthor
Known Participant
July 19, 2021

Thank you, @try67, for your answer!

I am pretty much new to all this PDF scripting world, so I am having a difficulties on writing such a condition. However, I have checked and made some research on the community that used event.source.name command in their scripts, and if I understand well, the condition should begin:

if (event.source.name & event.target.name = this.getField("Textfield-3").valueAsString + " " + this.getField("Textfield-4").valueAsString + ", " + this.getField("Textfield-5").valueAsString + ", " + this.getField("Textfield-6").valueAsString + ", " + this.getField("Textfield-9").valueAsString)

else this.getField     

 

I'm pretty sure this isn't the correct one, I would like to know if you could help me out in writing the code?

 

 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 19, 2021

Sure. Try this:

 

var fieldNames = ["Textfield-3", "Textfield-4", "Textfield-5", "Textfield-6", "Textfield-9"];
if (event.source && fieldNames.indexOf(event.source.name)!=-1) {
	event.value = this.getField("Textfield-3").valueAsString + " " + this.getField("Textfield-4").valueAsString + ", " + this.getField("Textfield-5").valueAsString + ", " + this.getField("Textfield-6").valueAsString + ", " + this.getField("Textfield-9").valueAsString;
}