Page 1 of 1
Problem tags #ryear within the script in Javascript
Posted: Sun 23 Apr 2023 7:03 pm
by mitmania
Hello, everyone. I have the following problem: I use the old version of Cumulus 1.9 and in the indexT.htm page I have inserted a javascript script to make comparisons in the rain value. My problem is that I cannot get in any way the numerical value of the #ryear tags to be inserted inside the script. Am I going down the wrong path ? Is this possible ? Thanks to those who can give me some answers.
Re: Problem tags #ryear within the script in Javascript
Posted: Mon 24 Apr 2023 10:14 am
by mcrossley
I think it would help if you posted your script and an indication of the lines causing the problem.
Re: Problem tags #ryear within the script in Javascript
Posted: Mon 24 Apr 2023 7:12 pm
by mitmania
Hi, I attach the indexT.htm code of my web page. I can't use the value of the #ryear tag to use within the script. Currently I calculate only a theoretical value of rainfall.
Code: Select all
!-- Sez_Rain_Wind_line_5 -->
<tr class="td_temperature_data">
<td><font size="3">Descrizione</font></td>
<td><#beaudesc></td>
<td><font size="3"> Pioggia anno</font></td>
<td><#ryear> <#rainunit></td>
</tr>
<!-- Sez_Rain_Wind_line_6 -->
<tr class="td_temperature_data">
<td><font size="3">Direzione dominante vento</font></td>
<td><#domwindbearing>°</td>
<td><font size="3"> Giorni dall'ultima pioggia (> 0.2mm)</font></td>
<td><#ConsecutiveDryDays></td>
</tr>
<!-- Sez_Rain_Wind_line_7 -->
<tr class="td_temperature_data">
<td><font size="3"> </font></td>
<td></td>
<td><font size="3"> Pioggia teorica dall'inizio anno </font></td>
<td><span id="valore"></span> <#rainunit></td>
<td>
<script type="text/javascript">
var oggi = new Date();
var inizioAnno = new Date(oggi.getFullYear(), 0, 1); // 1 = gennaio
var differenzaTempo = oggi.getTime() - inizioAnno.getTime();
var differenzaGiorni = Math.floor(differenzaTempo / (1000 * 60 * 60 * 24));
var pre_media_anno = 1214.1 // valore dal 2010 al 2022
var pre_media_giorno_teo = 3.3217 // valore teorico
var pre_giornox_teo = pre_media_giorno_teo * differenzaGiorni;
var pre_giornox_teo_int = Math.floor(pre_giornox_teo);
document.getElementById("valore").innerHTML = pre_giornox_teo_int;
</script></td>
</tr>
Re: Problem tags #ryear within the script in Javascript
Posted: Tue 25 Apr 2023 1:25 pm
by mcrossley
If you are using a decimal numeric web tag in a script with a comma decimal locale, then you must convert the comma to a full stop before it is used.
Cumulus MX can do this for you, but with C1 you will have to assign the value to a variable as text and then do a replace on ',' to '.' before you use the variable in a calculation.
Re: Problem tags #ryear within the script in Javascript
Posted: Tue 25 Apr 2023 6:29 pm
by mitmania
OK ....Thank you very much for your reply. This evening I will put into practice what you have indicated to me to do. Thanks again!