Skip to main content
B0nb0n12345
Participating Frequently
February 16, 2016
Answered

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

  • February 16, 2016
  • 1 reply
  • 1528 views

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?

This topic has been closed for replies.
Correct answer try67

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";

1 reply

try67
Community Expert
Community Expert
February 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.

B0nb0n12345
Participating Frequently
February 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"()()

{

}

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 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";