Jump to content

Red Font for > than Value


Recommended Posts

Follow the same stuff as here: 

Just change the fields to your own and there is also a comment if you only want to affect a single column: 


So it will be kinda like this:

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

<script>
var isi = document.getElementById("visi[@field:yourIDfield]");
if([@field:yourfield] > [@field:yourfield2]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

Note: You still need to change the column position(the number) and the field names to make it work for you DataPage. Cheers!

Link to comment
Share on other sites

hmm.

Here's how I edited it and it doesn't seem to work. I'm sure it's my fault.

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

<script>
var isi = document.getElementById("visi[@field:impervious#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

I go here to select the data field from this drop down.

Screenshot 2023-08-19 at 10.27.57 AM.png

Link to comment
Share on other sites

3 minutes ago, DavidBRX said:

hmm.

Here's how I edited it and it doesn't seem to work. I'm sure it's my fault.

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

<script>
var isi = document.getElementById("visi[@field:impervious#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

I go here to select the data field from this drop down.

Screenshot 2023-08-19 at 10.27.57 AM.png

what does it output right now? can you grab a screenshot?

Link to comment
Share on other sites

Oh in case you missed TellMeWhy's comment at the bottom of his reply, you will need a unique field or an autonumber of some sort for the  yourIDfield part

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

<script>
var isi = document.getElementById("visi[@field:yourIDfield]");
Link to comment
Share on other sites

Like this?

 

<div id="visi[@field:impervious#1]"></div>
<script>
var isi = document.getElementById("visi[@field:impervious#1]");
if([@field:impervious#1] > [@calcfield:1#2]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

Link to comment
Share on other sites

1 minute ago, DavidBRX said:

Like this?

 

<div id="visi[@field:impervious#1]"></div>
<script>
var isi = document.getElementById("visi[@field:impervious#1]");
if([@field:impervious#1] > [@calcfield:1#2]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

Not really. It needs to be another field in your table. Go to the table that you are using for your DataPage and check the  "Table Design" tab and see if you have any field that is set as "unique" (unique checkbox is checked) or a field using the Data type "Autonumber" or "Random ID" or "GUID".  The reason behind that is because the parentNode function needs to know which row is the parent, And the identifier that we should use is unique so it wont get confused with another row when changing the colors.

Link to comment
Share on other sites

Or maybe you can try [@cbRecordIndex#]. I haven't really tried it but I found it in this official forum post and it is used in a similar fashion.


<div id="visi[@cbRecordIndex#]"></div>
<script>
var isi = document.getElementById("visi[@cbRecordIndex#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

try this and remember to change (1) to the position of the column that you are trying to change. Try 6 or 7 maybe

Link to comment
Share on other sites

Just now, Tubby said:

Or maybe you can try [@cbRecordIndex#]. I haven't really tried it but I found it in this official forum post and it is used in a similar fashion.


<div id="visi[@cbRecordIndex#]"></div>
<script>
var isi = document.getElementById("visi[@cbRecordIndex#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(1)").style.color="red";
}
</script>

try this and remember to change (1) to the position of the column that you are trying to change. Try 6 or 7 maybe

Try this first and if it doesn't work, then yes. Add a new field and assign it as Autonumber then replace the [@cbRecordIndex#] in my pasted code and the (1) to (7).

Link to comment
Share on other sites

Tried this:

<div id="visi[@cbRecordIndex#7]"></div>
<script>
var isi = document.getElementById("visi[@cdRecordIndex#7]");
if([@cbRecordIndex#7] > [@cbRecordIndex#6]){
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
</script>

Added the number to the table, and still no luck. :-(

Screenshot 2023-08-19 at 11.07.12 AM.png

Link to comment
Share on other sites

20 minutes ago, DavidBRX said:

Tried this:

<div id="visi[@cbRecordIndex#7]"></div>
<script>
var isi = document.getElementById("visi[@cbRecordIndex#7]");
if([@cbRecordIndex#7] > [@cbRecordIndex#6]){
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
</script>

Added the number to the table, and still no luck. :-(

Screenshot 2023-08-19 at 11.07.12 AM.png

dont add numbers to the field names the number I am referring to is just the thing next to td:nth-child. Let me fix that for you:
<div id="visi[@cbRecordIndex#]"></div>
<script>
var isi = document.getElementById("visi[@cdRecordIndex#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="black";
}
</script>

Also changed the color in the "else" statement to black because else will be the default in case imprevious is NOT higher than 30%

For your other question, it should be on an HTML block. Add one on your Results Page.

image.png.5046b6e1d5ef46c3e8f9537a137efc37.png

Link to comment
Share on other sites

WAIT!  We alomst have it! :-)

<div id="visi[@field:number#]"></div>
<script>
var isi = document.getElementById("visi[@field:number#]");
if([@field:impervious#] > [@calcfield:1#]){
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(7)").style.color="black";
}
</script>

I just need the "actual" column in red not the 30% before it.

 

YES, we're close!!!

Screenshot 2023-08-19 at 11.40.04 AM.png

Link to comment
Share on other sites

OK we almost have it.  THANK YOU SOOOO MUCH!

The only thing is it's not consistent.  The objective is to FLAG/RED FONT whenever the ACTUAL COLUMN exceeds the 30% COLUMN

You can see in four cases it's not catching it. :-(

I know this is probably an entirely different issue and you've been most helpful with the original isle at hand.

Screenshot 2023-08-19 at 11.45.34 AM.png

Link to comment
Share on other sites

Wait!  I removed the # symbol from the following code and that seems to have solved it.

 

<div id="visi[@field:number#]"></div>
<script>
var isi = document.getElementById("visi[@field:number#]");
if([@field:impervious] > [@calcfield:1]){
isi.parentNode.parentNode.querySelector("td:nth-child(8)").style.color="red";
}
else{
isi.parentNode.parentNode.querySelector("td:nth-child(8)").style.color="black";
}
</script>

Link to comment
Share on other sites

Glad that you are able to fix it yourself. Was just reading your replies now. Check your other records. I think the problem was with the format of Caspio's number where if you reach thousands, it adds a comma (,) that is not able to be compared as numbers causing the condition to fail. While removing the # works for commas, it removes, decimal values. (# represents number format in Caspio, removing it will make the number an integer, which has no decimals.) Check if values with only decimals as difference still works. If not, it will be need some additional lines of code to workaround it

Link to comment
Share on other sites

Hello Tubby,

 

You're absolutely AMAZING!  Thank you sooooo much for your time and expertise on this.

Ironically, for some odd reason (unknown to me), I removed the # symbol wherever referenced, and this seems to have fixed it. It now calculates all the figures correctly (see attached). Of course I welcome your feedback on why this happened so I can hopefully understand what happened behind the scene when I removed the # from the code.  My brain is melting now. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...