Page 1 of 1

HTML "wood for the trees" issue!!

Posted: Wed 17 May 2017 1:35 pm
by mikechristelow
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!

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

Posted: Wed 17 May 2017 1:47 pm
by steve
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" /> .')

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

Posted: Wed 17 May 2017 2:19 pm
by mikechristelow
Thank you Steve - it's amazing what you can't see until someone else has a look at it!
Much appreciated,
Mike