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

Create a button that runs javascript in a text field

New Here ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Hi,

I'm extremely new to this and need some help. I have created a form that has a script to generate a purchase order number (date, time, etc.) but unless the user actually clicks in the field or tabs across it, the action does not complete. So if there is a way for the number to auto-populate upon saving the document, I figured my only way was to create a button (Create P0#) that the requestor or manager can create upon the button press.

Text field = workOrderNumber

JavaScript =

var f = this.getField("workOrderNumber");
var d = new Date();
var df = util.printd("mmddyyyy-HH-MM-", d)

if (f.value == "") {
    f.value = df + Math.round(Math.random() * Math.pow(2, 5));
}

Any advice would be greatly appreciated.

Thanks,
Will

(Using Adobe Acrobat Pro DC)

TOPICS
General troubleshooting

Views

2.0K

Translate

Translate

Report

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
Engaged ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

This might be an issue with where you are placing the JS.   Instead of executing the JS 'on enter' of the frame, try the following:

1. Create an advanced action 'on enter' 

2. For the first Action choose 'delay next action by' and put in .01 seconds

3. The next action should be to execute your JS.  

If this works (which it might not), it's because the JS is being executed before the elements on the page have loaded.  This (if it does work) is sometimes a really easy workaround.

Votes

Translate

Translate

Report

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 ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Hi Jeremy,

I'm using Adobe Acrobat Pro DC and under the actions of the textfield and the action under the button, I don't see a way to create an advanced action on enter.

If possible, I'd like to eliminate the need for the button all together but if it is necessary to execute the script in the textfield box, then so be it. Am I misunderstanding what you are saying? Remember, my knowledge of Adobe is basically nonexistent.

Thanks,

Will

Votes

Translate

Translate

Report

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
Engaged ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

Sorry I didn't see the Adobe Acrobat Pro part. I thought you were using Captivate.

Votes

Translate

Translate

Report

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 ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

I am also wondering if this is a question related with Captivate at all?

Please, which Adobe application are you using? I could move your question to the appropriate forum.

Votes

Translate

Translate

Report

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 ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

I'm sorry - I didn't realize I posted in the wrong program section. I'm using Adobe Acrobat Pro DC

Votes

Translate

Translate

Report

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 ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

OK, will move your thread.

Votes

Translate

Translate

Report

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 ,
Nov 29, 2017 Nov 29, 2017

Copy link to clipboard

Copied

LATEST

This post should be moved to the Acrobat JavaScript forum.

But, Ideally, the place to put the script is on the Document Save Action. But this will update the number every time the form is saved. Every time. If you want the number to only be set once per user, then that's more complicated.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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