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

Populate Text Field with Random Array Item on Button Press?

New Here ,
Dec 29, 2016 Dec 29, 2016

I am completely new to Javascript and Acrobat both.  I have a trial copy of Acrobat 9 that I'm working with.

I want to have a button (call it "GetThing") that when pressed will populate a text field (call it "RandomThing") from an array of items.  I came across this code but am unsure of where to insert it (in the button? in the text field? both?) and unsure of exact syntax.

var myArray = ['January', 'February', 'March'];

var randThing = myArray[Math.floor(Math.random() * myArray.length)];

That seems like it will define the array and get a random value from it, but how can I get the variable randThing to actually show up in the text field when the button is pressed?

Thank you!

TOPICS
PDF forms
968
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 29, 2016 Dec 29, 2016

At the end of the code add this line and then place it as the button's MouseUp script:

this.getField("RandomThing").value = randThing;

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 ,
Dec 29, 2016 Dec 29, 2016

At the end of the code add this line and then place it as the button's MouseUp script:

this.getField("RandomThing").value = randThing;

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
New Here ,
Dec 29, 2016 Dec 29, 2016
LATEST

You, my friend, are amazing!  Thank you!

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