Page 1 of 1

webtags and javascript

Posted: Wed 12 Mar 2014 5:09 am
by upnaway
Hi, I have been modifying the stock HTML pages for sometime, but I am looking to expand my knowledge and functionality with some basic javascript. As javascipt in HTML is completely foreign to me, I am hoping someone can point me in the right direction of how some basic mods that use the Cumulus webtags in javascript.

What I am trying to achieve is a basic update to my Today page, where rather than display both Consecutive Rain Days and Consecutive Dry Days, it just displays one tag or the other depending on which tag is active and some corresponding descriptive text

What my table presently has is:
<tr class="td_rainfall_data">
<td>Consecutive&nbsp;Days&nbsp;of&nbsp;Rain</td>
<td><#ConsecutiveRainDays></td>
<td>&nbsp;</td>
</tr>
<tr class="td_rainfall_data">
<td>Days&nbsp;Since&nbsp;It&nbsp;Last&nbsp;Rained</td>
<td><#ConsecutiveDryDays></td>
<td>&nbsp;</td>
</tr>

Depending on which tag is greater than 0 I want it to display that particular table row.

Further down the track, I would start to like utilising some of the Boolean webtags. Hopefully I can work that out for myself once I can understand some of the basics how the webtags interact in javascript

Re: webtags and javascript

Posted: Wed 12 Mar 2014 7:46 am
by steve
Webtags just get replaced with values, so they don't really interact with javascript at all. So where you might put

Code: Select all

<script>
if (x > 0) {
  document.write("Value is greater than zero");
}
</script>
with a web tag you do the same

Code: Select all

<script>
if (<#ConsecutiveRainDays> > 0) {
  document.write("Value is greater than zero");
}
</script>
So for what you want to do, you might use, for example:

Code: Select all

<script>
if (<#ConsecutiveRainDays> > 0) {
  document.write("Consecutive rain days: <#ConsecutiveRainDays>");
} else {
  document.write("Consecutive dry days: <#ConsecutiveDryDays>");
}
</script>

Re: webtags and javascript

Posted: Wed 12 Mar 2014 7:49 am
by upnaway
wow, so simple once it is explained. I've tried learning Java before, but I get so confused with all the other languages I have learnt in the past. Maybe I need to get with the times :)

Re: webtags and javascript

Posted: Wed 12 Mar 2014 7:54 am
by steve
To avoid any future confusion you should get used to always calling this stuff "JavaScript" and never "Java", as the two are completely different animals used for different purposes. JavaScript is a very useful skill to learn, it's even used a lot outside web browsers these days. I know just enough now to be dangerous!

Re: webtags and javascript

Posted: Wed 12 Mar 2014 8:11 am
by upnaway
Shows how foreign I am, I didn't even realise there was a difference.

Thanks for your help, I threw the code in and it worked a treat. Hopefully the 95 day dry spell in Perth will be broken sometime soon to put the code to good use.