Changing the fill color of a field based on a condition

It is easy to change the fill color of a field based on a condition, such as when a number exceeds a certain amount. For example, the script (JavaScript) below changes the fill color of a field to yellow when the value is below 100 and red when the value is 100 and up.

Try it
1) From LiveCycle Designer, open the “Dynamic Purchase Order” sample form (Purchase Order Dynamic.xdp).
2) Select the Quantity field (numQty).
3) Select and the “exit” event if a user will be entering data in the field or select the “initialize” event when the field is populated with data.
4) Copy and paste the following script into the Script Editor and edit the fill color to suit your purpose. If you would like the fill color to change for both user entered data and populated data, copy and paste the script into both the “exit” and “initialize” events.

if (this.rawValue >= 100) //red
{
this.fillColor = “255,0,0″;
}
else
this.fillColor = “255,255,0″; //yellow

5) Test the script using the Preview PDF tab.

Tips
Use a numeric field with this script.
Make sure that you select JavaScript and run at the client.
Make sure that the “Preview Adobe XML Form As” property (in Form Properties) is set to “Dynamic XML Form”.
Use the “initialize” event to make the fill color change when the form is populated with data.
Use the “exit” event to make the fill color change when a user enters data.

For more LiveCycle Designer scripting samples, visit the LiveCycle Developer Center at http://www.adobe.com/devnet/livecycle/designer_scripting_samples.html/.

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 0.0/10 (0 votes cast)

Comments are closed.