These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Change color of field text using if then statement

Michael51
Registered: Jun 3 2008
Posts: 7

Hi
I have a simple 5 row 1 column table, row 1 is a header, row 2 and three are numeric fields, row 4 calculates the sum of row 2 and three, row five is a numeric field with a default value of 10. and the field is set to read only so that the user cannot change it.
What I am trying to do is have the text colour of row 4 change if the value is greater than that in row 5.

ie
if row 4.cell1 is >= to row5.cell1 then
row4.cell1 text color = "255,0,0"; // red
else row4.cell1 text color = "???,0,0"; //black ( I don't know the number for black)
endif

or something like this

Can you help.

My Product Information:
LiveCycle Designer, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
I made up a sample table from your description and tried this JavaScript in the Calculation event of the field that needs to change color.

//Add the values of the first two fields.
var mySum = Table1.Row1.Cell1.rawValue + Table1.Row2.Cell1.rawValue;
//Get the value of the default of the field at the bottom of the table.
var myDefault = Table1.Row4.Cell1.rawValue;
if(mySum > myDefault)
{
Table1.Row3.Cell1.font.fill.color.value = "255,0,0";
}
else
{
Table1.Row3.Cell1.font.fill.color.value = "0,0,0";
}
//Put the sum of the first two fields in the sum field.
this.rawValue = mySum;

You can see that the RGB value for Black is 0,0,0.

I'm not sure if this is the best way to do this or not. But it works for me. Maybe someone else could respond and say.

StevenD

Michael51
Registered: Jun 3 2008
Posts: 7
Thanks StevenD,

I tried your script and it work perfectly .

I am now trying to add more colums and unfortunately it does not work on additional colums.

I have tried direct referencing each cell with no luck.

Thanks again

Michael
StevenD
Registered: Oct 6 2006
Posts: 368
You should be able to copy the script from the first column and paste it into the calculate event for the correct field in the next column (same row) and rename the cell references such as now Cell2.

StevenD

Michael51
Registered: Jun 3 2008
Posts: 7
Thanks Again StevenD

Took your suggestion and it did not work when I made a multiple copy of the column.

What I did then was to make a table 2 columns x 5 rows and paste the script into the cells and this looked right until I entered some data and then the data from row2 cell 1 also went into row2 cell 2.

I then direct referenced the cells in the script and this worked

//Add the values of the first two fields.
var mySum = Table1.Row1.Cell2.rawValue - Table1.Row2.Cell2.rawValue;
//Get the value of the default of the field at the bottom of the table.
var myDefault = Table1.Row4.Cell2.rawValue;
if(mySum > myDefault)
{
Table1.Row3.Cell2.font.fill.color.value = "255,0,0";
}
else
{
Table1.Row3.Cell2.font.fill.color.value = "0,0,0";
}
//Put the sum of the first two fields in the sum field.
this.rawValue = mySum;

I also changed the addition to subtraction and every thing if terrific.

Thanks again Michael