Page 1 of 1

error and new record lights

Posted: Mon 07 May 2012 3:50 am
by Alan
Hello all, I am hoping that somebody may be able to help me with the code for this small problem that I have. I am incorporating red or green lights into a table and that works fine but what I would also like to be able to do is incorporate both red and green lights alongside each other when the condition var x=11 is met. The alternative to not being able to do this is to use a third color for condition 11. After a heck of a lot of experimenting and researching I am still unsuccessful and at a loss. Help would be greatly appreciated.
Thanks in advance.
Alan

<table class="data" width="auto" height="45px" border="0" cellpadding="0" cellspacing="0" align="center">

<td valign="bottom"><script type="text/javascript">
var x=11 <!--<#ErrorLight><#newrecord>/!-->
if (x == "10") {var pictures = "redlight.png";}
if (x == "01") {var pictures = "greenlight.png";}
if (x == "11") {var pictures = "redlight.png";}
{var pictures = "greenlight.png";} (in this arrangement of course only the green light remains active)

if (x == "00") {var pictures = "greenlight.png";hidden}
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... '+pictures+'"/>');
</script></td>
</table>

Re: error and new record lights

Posted: Mon 07 May 2012 7:10 am
by MickinMoulden
Alan wrote:Hello all, I am hoping that somebody may be able to help me with the code for this small problem that I have. I am incorporating red or green lights into a table and that works fine but what I would also like to be able to do is incorporate both red and green lights alongside each other when the condition var x=11 is met. The alternative to not being able to do this is to use a third color for condition 11. After a heck of a lot of experimenting and researching I am still unsuccessful and at a loss. Help would be greatly appreciated.
Thanks in advance.
Alan

<table class="data" width="auto" height="45px" border="0" cellpadding="0" cellspacing="0" align="center">

<td valign="bottom"><script type="text/javascript">
var x=11 <!--<#ErrorLight><#newrecord>/!-->
if (x == "10") {var pictures = "redlight.png";}
if (x == "01") {var pictures = "greenlight.png";}
if (x == "11") {var pictures = "redlight.png";}
{var pictures = "greenlight.png";} (in this arrangement of course only the green light remains active)

if (x == "00") {var pictures = "greenlight.png";hidden}
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... '+pictures+'"/>');
</script></td>
</table>
You are putting x as being 11, it will never be 10 or 01. It will always show a red light. Just put var x=<#ErrorLight><#newrecord>/ .
Also, with the qoutations it needs more work adding in the backslash like:

Code: Select all

document.write('<img src=\"http://home.exetel.com.au/retnuh/weather/images/pictures/'+pictures+'\"/>');
     </script></td> 
Alternatively, why don't you just make a picture of two lights together for each of the scenarios and skip all the Javascript altogether and just have
<img src="http://home.exetel.com.au/retnuh/weathe ... ecord>.png">

Re: error and new record lights

Posted: Mon 07 May 2012 9:47 am
by mcrossley
Or have...

<img src="images/pictures/red<#ErrorLight>.png"><img src="images/pictures/green<#newrecord>.png">

With the following images in your images folder..

red0.png = "red off"
red1.png = "red on"
green0.png = "green off"
green1.png = "green on"

Re: error and new record lights

Posted: Mon 07 May 2012 10:28 am
by Alan
Thank you Michael and Mark for your efforts,

I can see Mark that your suggestion would work beautifully. However, since posting my original request for help I have ploughed on and managed to achieve the required results, albeit via a far more cumbersome fashion of code.

<table class="data" width="100%" height="45px" border="0" cellpadding="0" cellspacing="0" align="center">

<td width="100%"align="center"valign="bottom"><script type="text/javascript">
var x=<#ErrorLight><#newrecord>
if (x == "10")
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... dlight.png"/>');

var x=<#ErrorLight><#newrecord>
if (x == "01")
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... nlight.png"/>');

var x=<#ErrorLight><#newrecord>
if (x == "11")
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... dlight.png"/>');
document. write('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
if (x == "11")
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... nlight.png"/>');

var x=<#ErrorLight><#newrecord>
if (x == "00")
document.write('<img src="http://home.exetel.com.au/retnuh/weathe ... '+pictures+'"/>');
</script></td>
</table>

Thanks and cheers!
Alan