Page 1 of 2

UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 31 May 2022 4:15 pm
by dazza1223
im playing with a bit off js to get the UV band to chance colour depending on the number ie None Low Medium High Very High etc


var uv = rawdata[45];
if (uv=="0"){var uvword="None";} else
if (uv=="3"){var uvword="<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;Low&nbsp;</span>";} else
if (uv=="6"){var uvword="<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;Medium&nbsp;</span>";} else
if (uv=="8"){var uvword= "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;High&nbsp;</span>";} else
if (uv=="11"){var uvword="<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;Very&nbsp;High&nbsp;</span>";} else
{ var uvword="";}
$("#UVone").html(uvword);

but it seems to not work when i put this on test page

<td><span id="UVone"></span>


so i was wounding if some one can spot the error in this bit off code


thank you

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 31 May 2022 9:52 pm
by ConligWX
sorry cant help there but noticed on your site the website isn't updating correctly or your file checks are looking at the wrong data.

https://www.davisworthing.co.uk/uploadstatus.php

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 31 May 2022 10:18 pm
by BCJKiwi
Both the Saratoga and MXUI templates have this feature managed by the ajaxCUwx.js and ajaxCUmx.js files respectively.
(MXUI borrows heavily from the original Saratoga ajax but also removes a lot and adds a lot more!)

If you view those templates that may help but just as likely confuse (as it did me!).

There are also Heat colour words in the Saratoga template.

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Wed 01 Jun 2022 7:47 am
by dazza1223
ConligWX wrote: Tue 31 May 2022 9:52 pm sorry cant help there but noticed on your site the website isn't updating correctly or your file checks are looking at the wrong data.

https://www.davisworthing.co.uk/uploadstatus.php
Oh thank you I will take a look at that but thank you for spotting it out

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Wed 01 Jun 2022 7:49 am
by dazza1223
BCJKiwi wrote: Tue 31 May 2022 10:18 pm Both the Saratoga and MXUI templates have this feature managed by the ajaxCUwx.js and ajaxCUmx.js files respectively.
(MXUI borrows heavily from the original Saratoga ajax but also removes a lot and adds a lot more!)

If you view those templates that may help but just as likely confuse (as it did me!).

There are also Heat colour words in the Saratoga template.
Yh that where i found the piece of the code and modified it to my own JS file but it seem that it should work but there maybe a small little error somewhere I can't see but I know there's a lot more brainy people on here here can actually spot it out straight away?

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Sun 05 Jun 2022 1:48 pm
by mcrossley

Code: Select all

var uv = rawdata[45];
if (uv=="0"){var uvword="None";} else
if (uv=="3"){var uvword="<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;Low&nbsp;</span>";} else
if (uv=="6"){var uvword="<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;Medium&nbsp;</span>";} else
if (uv=="8"){var uvword= "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;High&nbsp;</span>";} else
if (uv=="11"){var uvword="<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;Very&nbsp;High&nbsp;</span>";} else
{ var uvword="";}
$("#UVone").html(uvword);
You are declaring the variable uvword within each if block, so it will not be available outside those if statement blocks.

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Sun 05 Jun 2022 1:56 pm
by dazza1223
OK thanks mark will u be so kindly to adjust it so it will work?

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Sun 05 Jun 2022 8:34 pm
by BCJKiwi
Remove the var after each {

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 1:17 pm
by dazza1223
BCJKiwi wrote: Sun 05 Jun 2022 8:34 pm Remove the var after each {

Code: Select all

var uv = rawdata[45];
if (uv=="0"){ uvword="None";} else
if (uv=="3"){ uvword="<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;Low&nbsp;</span>";} else
if (uv=="6"){ uvword="<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;Medium&nbsp;</span>";} else
if (uv=="8"){ uvword= "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;High&nbsp;</span>";} else
if (uv=="11"){ uvword="<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;Very&nbsp;High&nbsp;</span>";} else
{ uvword="";}
$("#UVone").html(uvword);

ok ive tried that but it seem to not being working?

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:03 pm
by freddie
Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:11 pm
by mcrossley
freddie wrote: Tue 07 Jun 2022 2:03 pm Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Yes it would be best to do that...

Code: Select all

var uv = rawdata[45];
var uvword;
if (uv=="0"){ uvword="None";} else
if (uv=="3"){ uvword="<span ...

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:16 pm
by HansR
mcrossley wrote: Tue 07 Jun 2022 2:11 pm
freddie wrote: Tue 07 Jun 2022 2:03 pm Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Yes it would be best to do that...

Code: Select all

var uv = rawdata[45];
var uvword;
if (uv=="0"){ uvword="None";} else
if (uv=="3"){ uvword="<span ...
All true but I don't think it is the cause of failing.
Maybe @dazza could elaborate on what exactly fails? Does it show anything in the UVone element or does it show erroneous something?
As you compare strings is that truly the content of the rawdata or is it e.g. "0 " with as result the if statements all fail and you get an empty string in the html element. If uncertain add a console.log statement after each if-clause to see something.

Or go to stackoverflow.

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:18 pm
by HansR
freddie wrote: Tue 07 Jun 2022 2:03 pm Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Javascript is an invitation to bad programming :lol:

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:32 pm
by freddie
HansR wrote: Tue 07 Jun 2022 2:18 pm
freddie wrote: Tue 07 Jun 2022 2:03 pm Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Javascript is an invitation to bad programming :lol:
:lol: that's why I only touch it when necessary
javascript.jpg

Re: UV colour depending on the number ie None Low Medium High Very High

Posted: Tue 07 Jun 2022 2:58 pm
by dazza1223
freddie wrote: Tue 07 Jun 2022 2:32 pm
HansR wrote: Tue 07 Jun 2022 2:18 pm
freddie wrote: Tue 07 Jun 2022 2:03 pm Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Javascript is an invitation to bad programming :lol:
:lol: that's why I only touch it when necessary
javascript.jpg
:lol: :lol: :lol: :lol: :lol: :lol: