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

Javascript on a pdf form to change the colour of a field depending on the value in another field

Community Beginner ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

I have used the following code to change the colour of a text field in a PDF form depending on the value entered into that field.

var v = +event.value; {

if (v>=1 && v<=5) 

event.target.fillColor = ["RGB",0.537,0.776,0]; 

Can anyone suggest how I can modify this code to change the colour of another field?

I want to change the colour of field "Text453" depending on the number entered into field "RISK"

(I have posted this question on another forum.)

TOPICS
Acrobat SDK and JavaScript , Windows

Views

12.0K

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 , Jun 02, 2017 Jun 02, 2017

The correct syntax is to put the curly brackets after the if-condition. It works in your case because you only have one line of code associated with it, but it's not good practice. This is how it should look like:

var v = +event.value;

if (v == 1) {

    this.getField("Text803").fillColor = ["RGB",0.537,0.776,0];

} else {

    this.getField("Text803").fillColor = color.white;

}

Votes

Translate

Translate
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

can i add there be an option up top where they can change the font with pdf form?

where user change font size when filling form.?

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 28, 2019 May 28, 2019

Copy link to clipboard

Copied

LATEST

OK, that's not quite what you described. You can change the color of the entire field based on the selection made in it, but not of an individual item. And no, it's not likely to work on almost any mobile device.

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