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

Using JavaScripts to handle keypress events

Community Beginner ,
Feb 12, 2019 Feb 12, 2019

I am converting a HTML file into PDF using evoPDF library in a c# application. This PDF form has multiple textboxes and my requirement is to track keypress event or blur event for these textboxes. I am not able to find syntax on how to write these event  handling in Adobe JavaScript. Can someone guide me with these. Your help will be highly appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows
3.3K
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 ,
Feb 12, 2019 Feb 12, 2019

You can use the setAction method to apply a script to the Keystroke and OnBlur events of the fields.

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 Beginner ,
Feb 12, 2019 Feb 12, 2019

can you please guide me with the syntax to use it,

I am currently trying this:

pdfDocument.Form.Fields["txt_BorrowerHireDate"].Action = new PdfActionJavaScript("if(this.getField('txt_BorrowerHireDate').keyDown==true){app.alert('test');}");

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 ,
Feb 12, 2019 Feb 12, 2019

Sorry, I'm not familiar with the syntax of your C# library.

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 Beginner ,
Feb 12, 2019 Feb 12, 2019

If you were to write, just the adobe scripts how would you have written it.

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 ,
Feb 12, 2019 Feb 12, 2019

this.getField("txt_BorrowerHireDate").setAction("MouseDown", "app.alert(\"test\");");

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 ,
Feb 12, 2019 Feb 12, 2019

However, I think you need to find out how to apply the action directly to the field. What I posted above the code to apply the action using JS, but you wouldn't apply that code to the field itself...

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 Beginner ,
Feb 20, 2019 Feb 20, 2019

Thanks for your help try67, but as you said this is a JS code, I need syntax for adobe javascript (tried the above mentioned syntax but it did not work). Also I tried setting the action on document open and not specific action to the field, but it is not working.

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 ,
Feb 20, 2019 Feb 20, 2019

Can you see the code in the PDF file when you open the file in Adobe Acrobat?

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 Beginner ,
Feb 20, 2019 Feb 20, 2019

No, code can't be seen. But yes, I am able to log errors.

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 ,
Feb 20, 2019 Feb 20, 2019

What errors does you get?

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 Beginner ,
Feb 20, 2019 Feb 20, 2019

SyntaxError: missing ) after argument list

1:Doc:Open

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 Beginner ,
Feb 20, 2019 Feb 20, 2019

code: pdfDocument.OpenAction.Action = new PdfActionJavaScript("this.getField('txt_BorrowerHireDate').setAction('MouseDown', 'app.alert('test');');");

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 ,
Feb 20, 2019 Feb 20, 2019
LATEST

Try this:

PdfActionJavaScript("this.getField('txt_BorrowerHireDate').setAction('MouseDown', 'app.alert(\'test\');');");

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