If you use Cumulus, please donate Image

Please read this post before posting

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See this post for download

HTML "wood for the trees" issue!!

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderators: daj, TNETWeather

User avatar
mikechristelow
Posts: 162
Joined: Wed Feb 01, 2012 9:33 pm
Weather Station: Watson W8681 (solar)
Operating System: Windows 10
Location: Crewe, Cheshire
Contact:

HTML "wood for the trees" issue!!

Postby mikechristelow » Wed May 17, 2017 1:35 pm

I'm trying to create a line of code for one of my pages which says whether it's sunny, what the UV Index is, a description for the index value and an image selected to reflect the severity of the image.

If I write

Code: Select all

document.write(<#UV>+" ("+uv_name+")");
where <#UV> is the webtag and uv_name is a variable assigned in a javascript to indicate the UV index severity (Low, Moderate, high etc) I get Image
as expected (the UV value being 1 at the time).

If I write

Code: Select all

document.write('It is overcast at the moment and current UV Index is <#UV>+" ("+uv_name+")"+<img src="images/UV_index/uv_index_<#UV>.png" width="11" height="11" alt="UV index" title="UV index" /> .')
I get this Image.

In otherwords, the variable uv_name is being presented literally rather than it's value being shown.

The full javascript is this:

Code: Select all

               <!-- Description of sunshine and UV conditions - only output if sun is up -->
               <script type="text/javascript">
                  <!-- Description of sunshine conditions -->
                  var is_sun_up = <#IsSunUp>;
                  var is_sunny = <#IsSunny>;
                  var uv_val = <#UV>;
                  var uv_name = "";
                  switch(true)
                  {
                  case uv_val == 0:
                  var uv_name = "No Risk";break;
                  case uv_val <= 2:
                  var uv_name = "Low";break;
                  case uv_val <=  5:
                  var uv_name = "Moderate";break;
                  case uv_val <=  7:
                  var uv_name = "High";break;
                  case uv_val <=  10:
                  var uv_name = "Very High";break;
                  case uv_val >=  11:
                  var uv_name = "Extremely High";break;
                  }                  
                  if (is_sun_up == 1)
                     {
                     <!-- Description of sunshine conditions -->                     
                     if (is_sunny == 0) // Not Sunny
                        {
                        document.write('It is not sunny at the moment and current UV Index is <#UV>+" ("+uv_name+")"+<img src="images/UV_index/uv_index_<#UV>.png" width="11" height="11" alt="UV index" title="UV index" /> .')                        
                        }
                     else
                        if (is_sunny == 1) // Sunny
                           {
                              document.write("It's sunny at the moment and current UV Index is "+uv_name+".");
                           }                     
                     }            
               </script>         


You'll see that the output for when it is sunny is simpler and this works.

I'm sure this must be something to do with nested quotes or something but I can't get this to work and need another pair of eyes on it. Any suggestions gratefully received!
http://www.christelow.co.uk
“It's snowing still," said Eeyore gloomily.
"So it is."
"And freezing."
"Is it?"
"Yes," said Eeyore. "However," he said, brightening up a little, "we haven't had an earthquake lately.”


User avatar
steve
Cumulus Author
Posts: 26148
Joined: Mon Jun 02, 2008 6:49 pm
Weather Station: None
Operating System: None
Location: On tour in France
Contact:

Re: HTML "wood for the trees" issue!!

Postby steve » Wed May 17, 2017 1:47 pm

I can't see the images, but you are swapping quote types when you're not actually nesting, e.g. this quote

Code: Select all

<#UV>+"


should be the same as your opening quote

Code: Select all

<#UV>+'


Only the quotes in your <img ... /> construct need to be double quotes. You also have a missing quote before your <img tag (which you can simplify anyway):

Code: Select all

document.write('It is overcast at the moment and current UV Index is <#UV>+' ('+uv_name+')<img src="images/UV_index/uv_index_<#UV>.png" width="11" height="11" alt="UV index" title="UV index" /> .')
Steve
-----
Hosting available for Cumulus web sites. See http://sandaysoft.com/forum/viewtopic.php?f=2&t=11876

Like Cumulus and want to support it? Please donate! Image

User avatar
mikechristelow
Posts: 162
Joined: Wed Feb 01, 2012 9:33 pm
Weather Station: Watson W8681 (solar)
Operating System: Windows 10
Location: Crewe, Cheshire
Contact:

Re: HTML "wood for the trees" issue!!

Postby mikechristelow » Wed May 17, 2017 2:19 pm

Thank you Steve - it's amazing what you can't see until someone else has a look at it!
Much appreciated,
Mike
http://www.christelow.co.uk
“It's snowing still," said Eeyore gloomily.
"So it is."
"And freezing."
"Is it?"
"Yes," said Eeyore. "However," he said, brightening up a little, "we haven't had an earthquake lately.”



Return to “Web site - General”

Who is online

Users browsing this forum: No registered users and 3 guests