Copy link to clipboard
Copied
Hi,
I've looked and haven't found the easiest path to making my text field auto populate initials for a checklist. I have about 185 fields over 3 columns and know there must be an easier way than adding this script to each form field individually.
// check form field, if blank add initials, if initials make N/A, if N/A make blank
var initialsField= this.getField("RIC2").valueAsString;
if(initialsField==""){
this.getField("RIC2").value=this.getField("RICInitials").value;
}
else if (initialsField==this.getField("RICInitials").value){
this.getField("RIC2").value= "N/A";
}
else if (initialsField=="N/A"){
this.getField("RIC2").value= "";
}
Initially, I was going to paste that in the action tab with the on focus trigger and change the form field each time but I thought programmers are way smarter than that but I can't figure out what to do next.
I thought I could make a function in the main javascript part, I think that is called document level. Then I saw something about event.target.value but can't figure out how to make either work.
If you don't mind, all I want to change above is instead of putting the field name, some snippet of code that says "for your field name" or "take action in your field" so I dont have to change it to say "field1", "field2", "field3", etc. With that I can select all of the fields applicable and add all of the same action on focus run a javascripts at the same time.
Thank you for any guidance.
If you use it as "On focus" you can use this code and it will work in all fields:
var Initials = this.getField("RICInitials").valueAsString;
if(event.value == ""){
event.target.value = Initials;}
else if(event.value == Initials){
event.target.value= "N/A";}
else if(event.value == "N/A"){
event.target.value= "";}
Copy link to clipboard
Copied
Why does you use the on focus trigger?
On which field does you use it?
Copy link to clipboard
Copied
If you use it as "On focus" you can use this code and it will work in all fields:
var Initials = this.getField("RICInitials").valueAsString;
if(event.value == ""){
event.target.value = Initials;}
else if(event.value == Initials){
event.target.value= "N/A";}
else if(event.value == "N/A"){
event.target.value= "";}
Copy link to clipboard
Copied
Thank you ma'am, this is perfect. I'm new but really enjoying learning the abilities of PDFs and learning coding. Thank you!
Copy link to clipboard
Copied
The code you've shown is circular. Each time it is run it will change the field to the next value, going around in a circle.
Your explanation is a bit muddled, but it doesn't seem that this is what you are after.
The best thing for you to do is explain, as simply as possible, in clear, explicit, and complete language, exactly how you want this to work. If you have multiple rows of fields that require the same behavior, then also explain how the fields are named. This type of arrangment is best handled if the fields have a consistent naming scheme.
Then we can suggest a solution.
Copy link to clipboard
Copied
Thank you sir, I wanted it to be circular.
It's a checklist that some of my team has to use and one of my flight chiefs stated that manually typing in his initials in each block was tedious so this was an idea to click on a box and it autofills your initials. If that was a mistake, click on it again for it to go back to N/A or click again for it to become blank again.
I thought to use "on focus" so it works when tabbing through but I would like it to work with clicking multiple times in the text box without focusing elsewhere and coming back. What would you suggest for that? Thank you for the insight.