Page 1 of 2
Trend arrow Javascript
Posted: Sat 31 Jul 2010 2:26 pm
by Areco747
Hi !! I need help with this JavaScript indicating the temperature trend arrow (Up or down)
<td><#temp> <#tempunit><script type="text/javascript">
var temp = "<#temptrend>";
if (temp=="0"){var imagen = "steady.bmp";}
if (temp>"0"){var imagen = "up.bmp";}
if (temp<"0"){var imagen = "down.bmp";}
document.write('<img src="
http://arecoclima.com.ar/xxxxx/'+imagen+'"/>');
</script></td>
When trend is 0: is correct arrow steady and similar when trend is negative.(arrow down)
But when the trend is positive (example +1.2) continuous with the down arrow. Where I have the error?
Many thanks,
Mauricio
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 3:08 pm
by steve
I think the problem is that you are comparing strings, not numbers. I think you need:
Code: Select all
var temp = <#temptrend>;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 3:19 pm
by Areco747
Steve if I remove the quotes 0 instead of "0" continues the problem.
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 3:42 pm
by steve
Can you show me the page where you have this code?
I took a copy of your current page at
http://arecoclima.com.ar/, which had this code in it:
Code: Select all
var temp = "+1.3";
if (temp=="0"){var imagen = "steady.bmp";}
if (temp<"0"){var imagen = "up.bmp";}
if (temp>"0"){var imagen = "down.bmp";}
I edited the code to this:
Code: Select all
var temp = 0;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp1.png
I edited it to this:
Code: Select all
var temp = +1.3;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp2.png
I edited it to this:
Code: Select all
var temp = -1.3;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And I got this:
temp3.png
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 4:06 pm
by Areco747
Steve: The page is
http://www.arecoclima.com.ar/index.htm and the current code is:
var temp = "<#temptrend>";
if (temp=="0"){var imagen = "steady.bmp";}
if (temp<"0"){var imagen = "up.bmp";}
if (temp>"0"){var imagen = "down.bmp";}
But in this case by lowering the trend continues up arrow.
Now I change if (temp > "0") for if (temp<" 0 ") so that the arrow goes up, but this sunset when the negative trend is continue the arrow up and I have to modify the code again.
Thanks.
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 4:14 pm
by steve
I don't understand; you said you had removed the quotes as I suggested, but they are still there. The code you need, which I have tested in all three situations, is in my first reply.
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 4:48 pm
by Areco747
Steve: Now add your code without quotes and without quotes in <#temptrend>.
var temp = <#temptrend>;
if (temp==0){var imagen = "steady.bmp";}
if (temp>0){var imagen = "up.bmp";}
if (temp<0){var imagen = "down.bmp";}
And update to the site Ok.
I'll try it this afternoon with the temperature down if it responds.
Thank for you help !!!
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 8:44 pm
by Areco747
Steve, now with trend steady and down, update Ok.
Many Thanks!!
Re: Trend arrow Javascript
Posted: Sat 31 Jul 2010 11:34 pm
by steve
Muy bueno!
Re: Trend arrow Javascript
Posted: Sat 07 Aug 2010 9:44 am
by Palmyweather
I did my trends something like this:
E.G. Wind:
Code: Select all
<script type="text/javascript">
var windaverage = *VALUE*;
var windlatest = *VALUE*;
if (windlatest>windaverage)
document.write('<img src="dbimages/risingarrow.gif" width="7px" height="7px" align="absmiddle" border="0" alt="Current trend is " title="Current trend is rising" />');
else if (windlatest<windaverage)
document.write('<img src="dbimages/fallingarrow.gif" width="7px" height="7px" align="absmiddle" border="0" alt="Current trend is " title="Current trend is falling" />');
else
document.write('<img src="dbimages/steadyarrow.gif" width="7px" height="7px" align="absmiddle" border="0" alt="Current trend is " title="Current trend is steady" />');
</script>
And for those that are calculated by Cumulus software, something very simple like this:
Code: Select all
<img src="dbimages/<#temptrendenglish>arrow.gif" width="7px" height="7px" align="baseline" border="0" alt="Current trend is <#temptrendtext>" title="Current trend is <#temptrendtext>" />
So of course I named my arrows "Rising" "Falling" and "Steady". Works well for me. Will soon be introducing wind direction arrows based upon the latter principal.
Someone will probably find holes in what I have done but seems okay to me.
Re: Trend arrow Javascript
Posted: Sat 07 Aug 2010 2:52 pm
by GraemeT
I just thought I'd muscle in with my bit, too.
Not much good with javascript, so here's the php code I use:
Code: Select all
....html
<?php if ($temptrendenglish == 'Rising') echo '<img src="images/trendup.png" alt="" />';
else if ($temptrendenglish == 'Falling') echo '<img src="images/trenddn.png" alt="" />';
else echo '<img src="images/steady.png" alt="" />'; ?>
more html...
The same structure is used to show pressure trend.
...I wonder how many different ways there are of achieving a result...
Re: Trend arrow Javascript
Posted: Sun 08 Aug 2010 6:07 pm
by Areco747
This is my final work, thank you all!!
www.arecoclima.com.ar
Re: Trend arrow Javascript
Posted: Mon 15 Nov 2010 8:41 am
by corsair
Impossible to manage it... I try everything (I think...) Can you ,please, tell me what am I doing wrong???
Here is my page...
http://www.corsair.gr/wxpage/lc3600.html
Re: Trend arrow Javascript
Posted: Mon 15 Nov 2010 8:46 am
by steve
corsair wrote:Impossible to manage it... I try everything (I think...) Can you ,please, tell me what am I doing wrong???
It's the 'comma' decimal separator which Javascript doesn't understand. You can use the web tags which replace the comma with a decimal point, which are there for this purpose. There may be ways of getting Javascript to understand the commas; I don't know.
Re: Trend arrow Javascript
Posted: Mon 15 Nov 2010 8:47 am
by mcrossley