Skip to main content
Participating Frequently
June 7, 2024
Answered

Custom validation script doesn't work on certain text boxes

  • June 7, 2024
  • 2 replies
  • 2381 views

I have the following custom validation script on a text box:

varClientName = event.value;
this.getField("Client Name pg16").value = varClientName;
this.getField("Client Name pg17").value = varClientName;

to autopopulate names further in the document. In this example, the name successfully was added to text box "Client Name pg16", but not "Client Name pg17".  However, if I use "Prepare a Form" and I move text box "Client Name pg17" and then undo that move, the validation script does then work on that textbox.
I cannot possibly be expected to move each and every textbox each time I want to run a validation script. How can I solve this issue?

This topic has been closed for replies.
Correct answer try67

Do the other fields have a calculated value as well? If so, you need to check the fields calculation order, under More in Prepare Form mode.

2 replies

PDF Automation Station
Community Expert
Community Expert
June 7, 2024

There should be space after var to name the variable, and then no var with the next two client names like this:

 

var ClientName = event.value;
this.getField("Client Name pg16").value = ClientName;
this.getField("Client Name pg17").value = ClientName;

 

An easier way to write this script is:

this.getField("Client Name pg16").value = event.value;
this.getField("Client Name pg17").value = event.value;

 

However, I tested your script and it work for me.  Like Nesa Nurani said, just name all the fields the same, unless you need the user to be able to change the values after they have been validated, while leaving the value in the data entry field untouched.

 

 

Participating Frequently
June 14, 2024

Thanks for the help, I replaced my script with yours but unfortunately I'm still having the same issue. Only some of the boxes are autopopulated, but moving the unpopulated boxes in "Prepare a Form" mode then causes it to autopopulate when I try again. I've noticed it's certain pages that are the issue, but cannot figure out why.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 14, 2024

Do the other fields have a calculated value as well? If so, you need to check the fields calculation order, under More in Prepare Form mode.

Nesa Nurani
Community Expert
Community Expert
June 7, 2024

It should fill both fields at the same time, can you share your file with us?

If you wish to autopopulate those fields there is an easier solution, just give all 3 fields the same name, fields with the same name have the same value, there is no need for script.

Participating Frequently
June 14, 2024

Thank you for the help. Unfortunately I cannot share the document I'm sorry. Using the same label/name for each text box won't work for me either since some information will not be the same in each textbox, multiple people will be handling this document, and I do not want changes to a textbox further in the document to alter the information that was previously entered. My goal is to have the earlier textboxes autopopulate further down in the document, but allow changes to those later textboxes without alterring the earlier textboxes. I'm wondering if it's an issue of having too many textboxes and validation scripts in a single document?

try67
Community Expert
Community Expert
June 14, 2024

No, that's not likely. It's much more likely there's a problem with your code. Did you check the JS Console?