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

Fill in another text field based on previously entered text

New Here ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Hey there,

I am struggling a bit with my code, as I do not get it to work with my form. The current code I have is as follows:

var field1 = this.getField("Brand").valueAsString;

if (field1=="Samsung") event.value = "SM-G960F";

else if (field1=="Apple") event.value = "A2111";

else event.value = "";


The steps I followed were:

1) I created a text field named "Model" and made it "Read Only"

2) Under "Javascript", I created a new document JavaScript called "Model"

3) I filled in the code above, where the goal is as follows:

     - The code would start by retrieving the text field "Brand" to see what value has been filled in (i.e.   "Samsung"

    - If "Samsung" has been filled in, the "Model" field should display the string "SM-G960F"
    - If "Apple" was entered in the "Brand" field, the "Model" field should display the string "A2111"

    - If nothing has been filled in, then the field should stay empty.

The current error is as follows (I've cycled through quite a bit now):

 

TypeError: this.getField(...) is null
1:Document-Level:Model

 

But this seems strange to me, as the getField value is supposed to be null until it is filled in right? Or am I completely off with my thoughts?


I would be very grateful if one of you guys could help me out! Here are some screenshots as well:

 

Acrobat_nifyCqJqNJ.pngAcrobat_r9SiCoBPfD.png

TOPICS
Acrobat SDK and JavaScript

Views

660

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

correct answers 1 Correct answer

Community Expert , May 04, 2020 May 04, 2020

Use the script as calculation of field "Model".

Votes

Translate

Translate
Community Expert ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Use the script as calculation of field "Model".

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

What it's telling you is that the field name is incorrect. It is the "getField" function that is returning null, not the value. 

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
New Here ,
Jun 01, 2020 Jun 01, 2020

Copy link to clipboard

Copied

LATEST

Thanks both! Because of these answers, I realised my form wasn't in the correct mode (if anyone else is struggling: go to prepare form -> More -> Convert to form), which allowed me to se the calculation field. Thanks again!

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