cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic alter colour cell with JavaScript

0 Kudos

Hello Guys,

I'm facing the current problem:

I want change a colour cell depends on the value of the cell variable. I'm using the following JavaScript code on the initialize event of this cell

data.First.MainTable.Table1.Row1.Cell6::initialize - (JavaScript, client)

var numrows = xfa.resolveNodes("data.First.MainTable.Table1.Row1[*]").length;

for (var i = 0; i < numrows; i++)

{

    var LV_DATA = xfa.resolveNode("data.First.MainTable.Table1.Row1[" + i + "].Cell6");

   

    switch(LV_DATA){

       case LV_DATA <= "2":

            this.border.fill.color.value = "0, 153, 0";

            break;

       case LV_DATA >= "3" && LV_DATA <= "6":

            this.border.fill.color.value = "255, 255, 0";

            break;

       case LV_DATA> "6":

            this.border.fill.color.value = "255, 0, 0";

            break;

       default:

            this.border.fill.color.value = "255, 255, 255";

    }

}

My output values is:

With this output on collumn RISK Level i should get the first two cells red and the last one yellow.

Can you help me?

Accepted Solutions (1)

Accepted Solutions (1)

prajeshdesai
Contributor
0 Kudos

There are some syntax errors,

use of switch case is wrong.

in case, don't wrap value in double quote ("<val>") if you are using < (greater than) or >(less than).

and also if you are writing script on Cell6 than use this.rawValue to get it's value.

and also not getting why you are counting cells, and using for loop.

Try below,


data.#subform[0].Table1.Row1[0].Cell2::initialize - (JavaScript, client)

var LV_DATA = this.rawValue;

switch(true){

       case LV_DATA <= 1:

          this.border.fill.color.value = "0, 153, 0";

          break;

       case LV_DATA <= 2 && LV_DATA == 2:

          this.border.fill.color.value = "255, 255, 0";

          break;

       case LV_DATA <= 3:

          this.border.fill.color.value = "255, 0, 0";

          break;

    }

Hope this helps.

0 Kudos

Thanks Prajesh I was waitting your help

It works!

Answers (1)

Answers (1)

Former Member
0 Kudos

i think you need to check for LV_DATA.rawValue instead