Skip navigation
martinangell
Currently Being Moderated

Changing the colour of a field

May 10, 2012 7:09 AM

Tags: #java #acrobat #pdf #script #forms

On a form I'm making it's important that if the value of say 'field1' is less than the value of 'field2' that the appearance of 'field1' in some way changes. That being the colour of the font or maybe the background colour of the field (this is to alert the person processing the form).

 

If anyone could point me in the right direction it would be very much appreciated. I've been struggeling with this for quite awhile now.

 

Martin

 
Replies
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    May 10, 2012 8:20 AM   in reply to martinangell

    You will have to use JavaScript, something like the following as the custom Calculate script for field 1:

     

    // Get the value of the other field, as a string

    var s2 = getField("t2").valueAsString;

     

    // Get the value of this field, as a string

    var s1 = event.value;

     

    // If both fields are not blank and value of s1 is less than s2,

    // set background color to red, otherwise white

    event.target.fillColor = (s1 && s2) && (+s1 < +s2) ? color.red : color.white;

     

     

    Replace "t2" with the actual name of field2. You can also adjust the colors to suit your needs. To change the text color instead, use the textColor property, or the strokeColor property to alter the border color.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points