Skip to main content
Participating Frequently
January 25, 2019
Answered

Javascript to autofill text fields

  • January 25, 2019
  • 1 reply
  • 4896 views

I want to be able to type a word in one text field and have several others auto populate with the letters of that word.  For example, I want to type the word "christmas" in the text field "word1" and have a script turn the string into an array and autofill text field "word1a" with the letter "c", "word1b" with the letter "h", etc..

Is this possible with the javascript installed in acrobat?  Would the file built in Acrobat DC be able to be filled in by someone else on another computer with only Reader.

I know this is possible with javascript, just not sure how to make it work with Acrobat.

What I have been trying is (which does not work):

var w1=this.getField('word1');

var w1a=this.getField('word1a');

w1a.value=w1.charAt(0);

I have also tried to convert the string into an array, but have not had any luck.  Is this something that would be done in the Document Javascripts or can you do it in the "custom calculations scripts" for the text field.

I have been able type each letter in a text field and add them together to form the word, so that is a work around I I can not get the javascript to work to split the word apart.

This topic has been closed for replies.
Correct answer Thom Parker

There is obviously something that I am missing.  I understand the javascript and have tried that. 

This is what I typed in for the code:

var strWord4 = this.getField('strW4')

var word4 = strWord4.split("");

w4a.value=word4(0).value

This is what the javascript debugger is telling me.

TypeError: strWord4.split is not a function


the "getField()" function returns the field object. You want the value of the field.  This is a very common mistake.

var strWord4 = this.getField('strW4').value;

But you have other issues. The split function returns an array. Arrays values are accessed with the square brackets.

w4a.value=word4[0]; 

But, you don't need to split the string to get the first character. just use this

w4a.value = strWord4[0];

And what is "w4a" ? is it is field object? 

1 reply

Joel Geraci
Community Expert
Community Expert
January 25, 2019

Are you looking for a comb? Acrobat can do that for you automatically. In the field properties, just select the "comb of" property and put in the maximum length. You don't need separate fields, Acrobat will space them out for you.

Participating Frequently
January 25, 2019

I don't think that is what I am looking for.  What I am wanting to do is split a word that a person types into a text field into its individual letter later on in the document.  A way to make a puzzle to unscramble the letters.

I can do it in the reverse order with the following script in the "Custom Calculations Script" for the text field.

var word2=this.getField('w2');

word2.value=this.getField('w2a').value+this.getField('w2b').value+this.getField('w2c').value+this.getField('w2d').value+this.getField('w2e').value+this.getField('w2f').value+this.getField('w2g').value+this.getField('w2h').value+this.getField('w2i').value+this.getField('w2j').value+this.getField('w2k').value+this.getField('w2l').value+this.getField('w2m').value+this.getField('w2n').value

I would be able to address each letter of the word individually this way, it is just a little bit more difficult tab between each text field to enter the letters individually then it would be just to type the word in and let the program break out each letter of the string.

Thom Parker
Community Expert
Community Expert
January 25, 2019
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often