Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] HALP :) javascript error on site.

[SOLVED] HALP :) javascript error on site.

Reply
  #1 (permalink)  
Old 01-09-09, 06:41 AM
d-base d-base is offline
New Member
 
Join Date: Jan 2008
Location: Sofia
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question [SOLVED] HALP :) javascript error on site.

Hai guys

I'd greatly appreciate some help with this problem.

There's a script on my website for image replacement, it works fine but Internet Explorer returns an error that says
" 'src' is null or not an object "

Here's the script.

Any clues what's wrong with it? (once again, it works perfectly, just returns this error)
Code:
<script type="text/javascript"><!--

function pi ()
{
  var plaatjes = document.images;
  var aantal = plaatjes.length;
  
  for(i=0;i<=aantal;i++)
  {
   
    var plaatje = plaatjes[i];
    if(plaatje.src == "http://to old  image.gif")
    {
      plaatje.src = "http://to new image.gif";
    }
  }
}
//--></script>

<script type="text/javascript"><!--
window.onload = pi();
//--></script>
Gives the error at the line in red.

In Firefox's error console it says "plaatje is undefined"
The image urls are correct and the script as I said works, it replaces the images but I dunno why it returns this error.

Last edited by Nico; 01-09-09 at 07:57 AM. Reason: [code] Wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-09-09, 07:57 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
Remove the equal sign in this line:
Code:
for(i=0;i<=aantal;i++)
... it makes the loop run one time too much, hence you get the error.

EDIT:

And this line:
Code:
window.onload = pi();
.... should be:
Code:
window.onload = pi;
... with the parenthesis, you're calling the function. And if it's being called before the browser has parsed the full page, it's possible that you get this error too.

Last edited by Nico; 01-09-09 at 08:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-09-09, 03:08 PM
d-base d-base is offline
New Member
 
Join Date: Jan 2008
Location: Sofia
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Nico, thank you very much! Your solution solved the error!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script Help Site JarodIcefire General Advertisements 0 03-23-06 11:05 AM
redirectin to a secure site pkcidstudio HTML/XHTML/XML 4 02-03-06 02:21 PM
[turnkey] Lyrics site - $149 rightinpoint General Advertisements 0 01-31-06 06:54 PM
MyCash.info - Developed site for sale LK-47 General Advertisements 0 10-16-04 01:57 PM


All times are GMT -5. The time now is 05:05 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.