• 0
jgfeller

Change background color based on IF solution

Question

I am attempting to change the background color in a report search results page using an IF function.  I tried to use the following code but for some reason it does not work.  I am sort of new at this so I may just be missing something obvious but I cannot find it.

 

<script>

 

var isi = document.getElementById("visi[@field:id#]");

 

if ([@calcfield:1#] > 6){isi.parentNode.parentNode.style.backgroundColor = '#58ff33';}

 

else if([@calcfield:1#] <= 6 && [@calcfield:1#] >= 4){isi.parentNode.parentNode.style.backgroundColor = '#ffac33';}


 

else if([@calcfield:1#] < 4){isi.parentNode.parentNode.style.backgroundColor = '#ff3b33';}

 

</script>

 

 

Share this post


Link to post
Share on other sites

1 answer to this question

  • 0
On 2/6/2017 at 7:59 PM, jgfeller said:

I am attempting to change the background color in a report search results page using an IF function.  I tried to use the following code but for some reason it does not work.  I am sort of new at this so I may just be missing something obvious but I cannot find it.

 

 


<script>

 



 

 


var isi = document.getElementById("visi[@field:id#]");

 



 

 


if ([@calcfield:1#] > 6){isi.parentNode.parentNode.style.backgroundColor = '#58ff33';}

 



 

 


else if([@calcfield:1#] <= 6 && [@calcfield:1#] >= 4){isi.parentNode.parentNode.style.backgroundColor = '#ffac33';}

 



 

 


else if([@calcfield:1#] < 4){isi.parentNode.parentNode.style.backgroundColor = '#ff3b33';}

 



 

 


</script>

 

 

 

You need to use string parameters, so try removing # symbol in parameter names, also make sure that you inserted opening div tag in html block above all the fields and closing div tag below all the fields. Also I would recommend removing if in the last condition. Use else instead of else if.

You may take a look at the code I use on my datapage:

html block1 above all the fields: 

<div id="visi[@field:id]">

html block2 below all the fields:

</div>
<script>var isi = document.getElementById("visi[@field:id]");

if('[@field:Sales]' >=1000)

{isi.parentNode.parentNode.style.backgroundColor = 'green';}

else

{isi.parentNode.parentNode.style.backgroundColor = 'red';}

</script>

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now