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

Javascript where text in Text Box A will trigger a text in Text box B?

New Here ,
Feb 16, 2016 Feb 16, 2016

Hello,

I've been trying to find a code in which a text in Text Box A will trigger text in Text Box B.  I am currently using a code that works when I type in the text on the form itself.  However, when I have the pdf file run through a program that pre-populates text in Text Box A, it won't trigger text in Text Box B.

I am using this code:

if (event.value!=" ") this.getField("Text Box B").value= 20

I am not sure if there something I have to change because text box A has a prepopulated text?

TOPICS
Acrobat SDK and JavaScript
1.4K
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

correct answers 1 Correct answer

Community Expert , Feb 16, 2016 Feb 16, 2016

Why all the added brackets and parentheses? It's not necessary.

Also, you're using the wrong operator in your if-statement. The comparison operator of JS is ==, not =. That's the assignment operator.

Use this code:

if (this.getField("Text Box A").valueAsString==" ") this.getField("Text Box B").value = "20";

Translate
Community Expert ,
Feb 16, 2016 Feb 16, 2016

You can place your code as a doc-level script, so that it executes when the file is first opened.

But then don't use event.value but this.getField("Text Box A").value, instead.

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 ,
Feb 16, 2016 Feb 16, 2016

Hello,

My code looks like this and I also placed it as doc-level script, but the text is still not showing up for Text Box B

if (this.getField("Text Box A").value=" ") this.getField("Text Box B").value= "20"()()

{

}

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 16, 2016 Feb 16, 2016

Why all the added brackets and parentheses? It's not necessary.

Also, you're using the wrong operator in your if-statement. The comparison operator of JS is ==, not =. That's the assignment operator.

Use this code:

if (this.getField("Text Box A").valueAsString==" ") this.getField("Text Box B").value = "20";

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 ,
Feb 16, 2016 Feb 16, 2016

Hello,

I used the code you provided, but nothing shows up in text box B after I run the pdf through the program...

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 17, 2016 Feb 17, 2016

Are you sure the value of the field is a single space, and not nothing, for example?

Also, check the JS console for error messages.

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 ,
Feb 17, 2016 Feb 17, 2016

Yes, im sure, and i even tested it on 2 other fields with actual text, but nothing

and no error messages

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 17, 2016 Feb 17, 2016

Where did you place the code, exactly?
Can you share the file (either privately or via Google Drive, Dropbox, Adobe Cloud, etc.)?

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 ,
Feb 17, 2016 Feb 17, 2016
LATEST

Hello,

i'll share the file via google drive.  I renamed some of the text boxes. 

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