Changing temp font color to red when non-frost and blue when frost?

This temp, in the main ajax dashboard:

This is the code that part use:

<span class="ajax" id="ajaxtemp" style="font-size:28px">
<?php echo strip_units($temperature) . $uomTemp; ?> 
</span>

Would it be possible to add a “if” function or something here?

Like if temp is > 0.0 then red font, and < 0.0 blue font?

Best Regards,
Martin

Hi Martin

write after
// — end of settings -------------------
the code

if ($temperature > 0) {
$colortemp = “#FF0000”;
}
if ($temperature < 0) {
$colortemp = “#0000FF”;
}

and add the code

before

<?php echo strip_units($temperature) . $uomTemp; ?> and add

regards
Panos

Hi Panos!

That works great, thank you!

Only 1 problem though, this code needs to go into the AjaxWDwx.js too, because when the AJAX script kicks in the temperature color reverts back to black.

This is the code in that file which needs to be changed:

temp = convertTemp(clientraw[4]);
set_ajax_obs("ajaxtemp", temp.toFixed(1) + uomTemp);

I am going to try to figure it out myself, but I think this is Java code, right? So it needs to be different from the previous code.

Best Regards,
Martin

Its showing Red to me even after the ajax has done its bit :wink:

Bashy, that’s probably because the AJAX didn’t update properly. I’m currently testing the code,
so sometimes the code isn’t working and the red font stays because the AJAX doesn’t update
when it’s not working.

This is what the code looks like now:

temp = convertTemp(clientraw[4]);
if (temp >= 0.0) {
   set_ajax_obs("ajaxtemp", temp.toFixed(1) + uomTemp);
   ajaxtemp.style.color = nofrostcolor;
} else {
   set_ajax_obs("ajaxtemp", temp.toFixed(1) + uomTemp);
   ajaxtemp.style.color = frostcolor;
}

Thing is, the flashcolor parameter is overriding the color… Need to get some help on this, this is basically as far as I can go on my own. :lol:

Best Regards,
Martin

Ah, ok m8, hope ya get it sussed :slight_smile:

Hi Martin,

What you want is doable, but it will require a bit of code change to prevent interference and reset by the ‘green flash’ mechanism.

The existing functions in ajaxWDwx.js as

function reset_ajax_color( usecolor ) {
// reset all the <span class="ajax"...> styles to have no color override
      var elements = get_ajax_tags();
	  var numelements = elements.length;
	  for (var index=0;index!=numelements;index++) {
         var element = elements[index];
	     element.style.color=usecolor;
 
      }
}

function set_ajax_obs( name, value ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs

		var element = document.getElementById(name);
		if (! element ) { return; } // V1.04 -- don't set if missing the <span id=name> tag
		var lastobs = element.getAttribute("lastobs");
		element.setAttribute("lastobs",value);
		if (value != unescape(lastobs)) {
          element.style.color=flashcolor;
		  if ( doTooltip ) { element.setAttribute("title",'AJAX tag '+name); }
		  element.innerHTML =  value; // moved inside to fix flashing issue (Jim at jcweather.us)
		}
}

could be amended to add a new function


function set_ajax_obsNF( name, value ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs
// no color change

		var element = document.getElementById(name);
		if (! element ) { return; } // V1.04 -- don't set if missing the <span id=name> tag
		var lastobs = element.getAttribute("lastobs");
		element.setAttribute("lastobs",value);
		if (value != unescape(lastobs)) {
//          element.style.color=flashcolor;
		  if ( doTooltip ) { element.setAttribute("title",'AJAX tag '+name); }
		  element.innerHTML =  value; // moved inside to fix flashing issue (Jim at jcweather.us)
		}
}

then change the calc for bigtemp to be

temp = convertTemp(clientraw[4]);
var element = document.getElementById("ajaxtemp");
if (temp >= 0.0) {
   set_ajax_obsNF("ajaxtemp", temp.toFixed(1) + uomTemp);
   if(element) {element.style.color = nofrostcolor;}
} else {
   set_ajax_obsNF("ajaxtemp", temp.toFixed(1) + uomTemp);
   if(element) {element.style.color = frostcolor;}
}

Then change the

<span class="ajax" id="ajaxtemp">

to be

<span class="ajaxNF" id="ajaxtemp">

so the reset_ajax_color() function won’t find and change the color to ‘’ (nil).

Hope this helps…

Best regards,
Ken

Ken,

Works perfectly, as usual!

It was something like that I’d imagine needed to be done, but the problem was figuring out how to accomplish that.
Thanks you so much Ken, and I wish you a happy birthday!

You can check the “reborn” bigtemp here: http://www.berdalweather.net/index.php

Best Regards,
Martin

SWEET!!!

You’re very welcome, Martin! Thanks for the kind wishes!

I don’t envy you the outside temp (you’re at -8C at 22:00) We’re at +8C for our overnight low :slight_smile:

Best regards,
Ken

Well, the clouds are coming closer in a few hours and the forecasts says some snow in the night and tomorrow. It will be the first real snow at my altitude, the peaks around here are already white. :slight_smile:

+8C for overnight low is higher than many of the overnight lows we had here in July. :lol:

Best Regards,
Martin

Hi Ken,

Are all of these changes in ajaxWDwx.js???

8O 8O

Thanks,

John