|
Post by xmas1313 on Jun 1, 2005 11:46:04 GMT -5
Gordon...
;D Glad you got it working! Incidentally, if you ever want to move the declarations above the <body> tag (or anyone can find out the proper way to declare multiple lines of JavaScript code within the body), here's some JavaScript for making the barometer always come out as xx.xx instead of getting "30" when it is "30.00"...
var baro=(Math.round(<!--barometer-->*100))/100; var baro=new String(baro); intLength=baro.length; if (intLength==4){baro+='0';} if (intLength==2){baro+='.00';}
The 1st line is the code I gave you, the 2nd line converts the barometer value to a string, the 3rd line gets the length of the string, the last 2 lines add zeros (if needed) to get xx.xx.
There may be an easier way to do this (maybe with precision type syntax), but this does work.
Scott
|
|
|
Post by Admin on Jun 1, 2005 12:05:09 GMT -5
Use this Javascript, substituting the <!--outsideTemp--> tag with whichever one is appropriate (and then also changing the word "temp" to "dp" or "hum" or whichever).
<script language="javascript"> temp = Math.round(<!--outsideTemp--> ) document.write(temp) </script>
|
|
|
Post by gclarkso on Jun 2, 2005 8:47:37 GMT -5
Gordon... ;D Glad you got it working! Incidentally, if you ever want to move the declarations above the <body> tag (or anyone can find out the proper way to declare multiple lines of JavaScript code within the body), here's some JavaScript for making the barometer always come out as xx.xx instead of getting "30" when it is "30.00"... var baro=(Math.round(<!--barometer-->*100))/100; var baro=new String(baro); intLength=baro.length; if (intLength==4){baro+='0';} if (intLength==2){baro+='.00';} The 1st line is the code I gave you, the 2nd line converts the barometer value to a string, the 3rd line gets the length of the string, the last 2 lines add zeros (if needed) to get xx.xx. There may be an easier way to do this (maybe with precision type syntax), but this does work. Scott Scott, So let me be clear: I insert the above in the <head> section of my page and then reference it the <body> using <script>document.write(baro)</script>...? If so, why did it take me this long to figure it out! LOL! Thanks, Gordon
|
|
|
Post by xmas1313 on Jun 2, 2005 22:25:20 GMT -5
Gordon...
Yep. Just make sure the variable name(s) in the <head> matches the variable name(s) you reference in the <body>. I still use the method you used when there's a value I need to do a straight one-time conversion on and don't need the variable anywhere else in the html.
Scott
|
|