471,594 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Variable scope - 2

Can anybody explain why my variable imonline is still 1 even though my
onError function has fired , value = 0 when printed by Javascript
document.write at end. I thought that
VAR imonline = 1
should have given me a global variable

var imonline = 1;
function imageError(theImage) {imonline=0; document.JWonline.src =

<BODY BGCOLOR="#b5ccb8">
<H2><CENTER>Is the green button loaded 2</CENTER></H2>
<!-- 2_greenx.jpg does not exist for this test -->
<img name="JWonline" src="2_greenx.jpg" align=left border=0

<p>Yellow button indicates offline<br>
Green button indicates online

<!-- since yellow button is on, so imonline should be 0 -->


John Wood
Jul 20 '05 #1
1 2406
John Wood <jo**@lortim.demon.co.uk> writes:
Can anybody explain why my variable imonline is still 1 even though my
onError function has fired

No it hasn't. When your document.write is executed, the image is still
being loaded (or waiting to fail loading). It will probably not finish
loading/failing the image before the page has been fully processed.

Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Grant Wagner | last post: by
4 posts views Thread by Gery D. Dorazio | last post: by
23 posts views Thread by Russ Chinoy | last post: by
1 post views Thread by pbmods | last post: by
2 posts views Thread by Shraddha | last post: by
112 posts views Thread by istillshine | last post: by
3 posts views Thread by SRoubtsov | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.