Copy link to clipboard
Copied
Hi,
I have tried a few different bits of code but I can't get this to work, I am trying to get text color to change but not the background colour.
I am after is that if the value of the cell (on page 3 the oxygen saturation) is between 0-86 the text goes red, if its 87-93 it goes magenta, 94-100 its green and any other value its black.
I tried this but it only changes the color to cyan and nothing else
var v = Number(event.value);
v = v.toFixed(2);
if (v<=86){event.target.textColor = color.red;}else if (v>87 && v<=93){event.target.textColor = color.magenta;}else if (v>95 && v<=100){event.target.textColor = color.green;}else{event.target.textColor = color.black;}
Any help would be great.
I don't see this code anywhere in the file. I placed it as the custom Validation script of one of those fields and it worked fine, except for when you enter 87, 94 or 95 and then it shows the text in black, since those values are not covered by your if-conditions properly. Use this code, instead:
var v = Number(event.value);
if (v <= 86) {
event.target.textColor = color.red;
} else if (v <= 93) {
event.target.textColor = color.magenta;
} else if (v <= 100) {
event.target.textColor
...
You didn't place the code in the right place. See my previous reply.
And yes, you can specify any RGB value you want, using this format:
event.target.textColor = ["RGB", 100/255, 20/255, 0/255];
Copy link to clipboard
Copied
I don't see this code anywhere in the file. I placed it as the custom Validation script of one of those fields and it worked fine, except for when you enter 87, 94 or 95 and then it shows the text in black, since those values are not covered by your if-conditions properly. Use this code, instead:
var v = Number(event.value);
if (v <= 86) {
event.target.textColor = color.red;
} else if (v <= 93) {
event.target.textColor = color.magenta;
} else if (v <= 100) {
event.target.textColor = color.green;
} else {
event.target.textColor = color.black;
}
Copy link to clipboard
Copied
Thanks, that is working nicely, the only thing I am finding is the text automatically goes to red then switches to black if it is in that range, is there a way that the standard colour is black then it changes to others if its in those ranges, also do you know if the javascript supports RGB colour codes or just the colour names? - I have uploaded a refreshed version with the code, I forgot to put it in the first one
Copy link to clipboard
Copied
You didn't place the code in the right place. See my previous reply.
And yes, you can specify any RGB value you want, using this format:
event.target.textColor = ["RGB", 100/255, 20/255, 0/255];
Copy link to clipboard
Copied
You are amazing, if I could buy you a drink I would, I have spent ages trying to get this to work and it is all because I read your reply to quickly and put something in the wrong place.
Copy link to clipboard
Copied
You can! http://PayPal.Me/try67
🙂
Copy link to clipboard
Copied
It seems like you’re close, but there are a few tweaks needed to get your code working as expected! First, let's correct the logic in the conditions and address why only cyan might have been showing up.
Here’s the corrected code:
var v = Number(event.value);
v = v.toFixed(2);
// Ensure the entire range is covered correctly
if (v >= 0 && v <= 86) {
event.target.textColor = color.red;
} else if (v >= 87 && v <= 93) {
event.target.textColor = color.magenta;
} else if (v >= 94 && v <= 100) {
event.target.textColor = color.green;
} else {
event.target.textColor = color.black; // For values outside the expected range
}
Key Fixes:
1. Ranges and conditions: Ensure each range is inclusive of the correct values. In your original code, the range between 86 and 87 wasn’t covered properly, so it might have been defaulting to black or another issue.
2. Boundary conditions: Using >= and <= ensures the boundaries like 87 or 94 are covered exactly.
Also, while you're tweaking this, it’s a good time to remember the importance of self-care! Sitting for long periods or focusing intensely on these problems can cause discomfort. Consider using products like the
Hi,
I have tried a few different bits of code but I can't get this to work, I am trying to get text color to change but not the background colour.
I am after is that if the value of the cell (on page 3 the oxygen saturation) is between 0-86 the text goes red, if its 87-93 it goes magenta, 94-100 its green and any other value its black.
I tried this but it only changes the color to cyan and nothing else
var v = Number(event.value);
v = v.toFixed(2);if (v<=86){event.target.textColor = color.red;}else if (v>87 && v<=93){event.target.textColor = color.magenta;}else if (v>95 && v<=100){event.target.textColor = color.green;}else{event.target.textColor = color.black;}
Any help would be great.
By @johnm47548927
Nooro Leg for leg pain relief to stay comfortable an
d productive! Keep coding!
Hi,
I have tried a few different bits of code but I can't get this to work, I am trying to get text color to change but not the background colour.
I am after is that if the value of the cell (on page 3 the oxygen saturation) is between 0-86 the text goes red, if its 87-93 it goes magenta, 94-100 its green and any other value its black.
I tried this but it only changes the color to cyan and nothing else
var v = Number(event.value);
v = v.toFixed(2);if (v<=86){event.target.textColor = color.red;}else if (v>87 && v<=93){event.target.textColor = color.magenta;}else if (v>95 && v<=100){event.target.textColor = color.green;}else{event.target.textColor = color.black;}
Any help would be great.
By @johnm47548927