Highlighted

Fill in another text field based on previously entered text

New Here ,
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

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the script as calculation of field "Model".

Topics

Acrobat SDK and JavaScript, General troubleshooting, PDF forms

Views

262

Likes

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

Fill in another text field based on previously entered text

New Here ,
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

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the script as calculation of field "Model".

Topics

Acrobat SDK and JavaScript, General troubleshooting, PDF forms

Views

263

Likes

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
Adobe Community Professional ,
May 04, 2020

Copy link to clipboard

Copied

Use the script as calculation of field "Model".

Likes

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
Reply
Loading...
Adobe Community Professional ,
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. 

Likes

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

Copy link to clipboard

Copied

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!

Likes

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF