Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load Image 2

Status
Not open for further replies.

Billybonga

IS-IT--Management
Jun 22, 2002
72
GB
What I'm trying to do with the code is rather than having text saying "You are currently on-line" / "You are currently off-line", I want to show a small on/off image

Here is what I've come up with - only thing is : It doesn't work.


<html>
<head>

<script type="text/javascript">
<!--
var tempImage;

function checkOnlineStatus() {
var tempImage = new Image();
tempImage.onload = returnOnlineStatus;
tempImage.onerror = returnOfflineStatus;
tempImage.src = ' // this must point to the url of a valid image
}

function returnOnlineStatus() {
var onImage = new Image();
onImage.src = 'on.gif';
document.getElementById('onlineStatus').firstChild.nodeValue = onImage;
}

function returnOfflineStatus() {
var offImage = new Image();
offImage.src = 'off.gif';
document.getElementById('onlineStatus').firstChild.nodeValue = offImage;
}

//-->
</script>
</head>

<body onload="checkOnlineStatus();">

<div><img src="test.gif" id="onlineStatus" width="19" height="18"></div>
</body>
</html>


Thanks for any help with this
 
Here is what I've come up with

Don't you mean this is what Dan (BillyRayPreachersSon) came up with and you're now trying to use? At least give credit where credit is due.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Firstly I'd change the <img> tag to be name="onlineStatus" Not ID.

Then for the returnonlinestatus use..

Code:
document.onlineStatus.src='on.gif';

and obviously use same but with off.gif for the offline bit.

which will reduce your code by loads also.


 
Sorry kaht -
This post was copied from a reply i had given to Dan on another post of mine (In which I thanked him for his help) - "Here's what i've come up with" was a reply to Dan, informing him of what changes I had made to his code.

I'm no way taking credit for his code. When I wasn't getting a responce from that post I copied it into this post - sorry if it wasn't edited enough for you to fully understand


------

Thanks 1DMF for your hel p - I'll give it a try
 
Perhaps then, for future reference, you could include a link to the other post when following up on a question you've already posted about. That would give more insight to all of us letting us know what you've already tried, and what has already been suggested.

For the record, I knew the other thread existed but not necessarily everybody else that browsed this thread would.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
1DMF:
>> "which will reduce your code by loads also."
and also limit it to the IE browser only.

Billybonga:
you simply need to change
Code:
  document.getElementById('onlineStatus').firstChild.nodeValue =  onImage;

to
Code:
  document.getElementById('onlineStatus').src = onImage.src;

and likewise for the off image.

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
I would go with Jeff's solution, as it is DOM compliant, and thus more likely to work in more browsers.

1DMF's solution uses IE-style shortcuts to refer to elements, which may not work in all browsers (Firefox, for example).

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well that code works fine for me in IE, FireFox & Netscape.

Not sure why you are having problems with it jemminger.
 
1DMF, it still works because firefox forgives poor programming practices used by the legions of people still using the IE-proprietary "document.all" collection. look in firefox's javascript console and you will see the warning. this is not guaranteed to exist forever, and the simple fact is that you can program ONCE to the DOM standards, or you can continuously update your code to work with whatever the proprietary extension flavor of the day is.


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
DOM standards change like any other, and FoamCow would tell you that browser will always be backward compatible with older standards.

To be honest I can't be bothered to spend my life forever trying to keep up with the joneses or the standards.

If it works, great, when it stops working i'll fix it, at least it gives me something to do :p
 
>> "FoamCow would tell you that browser will always be backward compatible with older standards."

perhaps, but at some point comes the EOL cycle when deprecated features are no longer supported.

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Hmm, what I actually said was

Name one instance of a tag that is not supported 1 version on from when it was dropped?

Quite different really.
Once again, you show how well you miss a point to satisfy your own misunderstanding of fact.

Of course there will come a time when things get dropped. But they don't get dropped immediately it is decided to remove them from a documented standard.

To be honest I can't be bothered to spend my life forever trying to keep up with the joneses or the standards.

LMAO
1DMF <- -> The point




Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top