By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

referencing images with javascript

P: 2
Hi i have the following code that works fine in firefox but not IE?

function imgLoad ()
{
test = new Image();
test = "../gfx/nav_es/areas_over.gif";
document.getElementById('test').src = test;
}

<body onLoad="imgLoad()">

<img src="../gfx/nav_es/humano_over.gif" name="test" id="test">

i have also tried

function imgLoad ()
{
test = new Image()
test = "../gfx/nav_es/areas_over.gif"
document.images['test'].src = test;
}

but with no result. I think it goes without saying i'm learning this for the first time.

any help would be greatly appriciated.
Jan 31 '07 #1
Share this Question
Share on Google+
2 Replies

b1randon
Expert 100+
P: 171
Hi i have the following code that works fine in firefox but not IE?

function imgLoad ()
{
test = new Image();
test = "../gfx/nav_es/areas_over.gif";
document.getElementById('test').src = test;
}

<body onLoad="imgLoad()">

<img src="../gfx/nav_es/humano_over.gif" name="test" id="test">

i have also tried

function imgLoad ()
{
test = new Image()
test = "../gfx/nav_es/areas_over.gif"
document.images['test'].src = test;
}

but with no result. I think it goes without saying i'm learning this for the first time.

any help would be greatly appriciated.
The problem is that you're assigning "test" to a new Image object, then RE-assigning "test" to "../gfx/nav_es/areas_over.gif". Something like this should fix your problem:
Expand|Select|Wrap|Line Numbers
  1. function imgLoad ()
  2. {
  3.     var test = new Image();
  4.     test.src = "../gfx/nav_es/areas_over.gif";
  5.     document.images['test'].src = test.src;
  6. }
  7.  
Jan 31 '07 #2

P: 2
b1randon - I was aging at an alaming rate sat here, I can not thank you enough!
Jan 31 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.