Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
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

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
15.8K
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 , 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;

}

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

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.?

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

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