Reply
For loop inside onload(); Adding events not working. :S
Old 01-23-2008, 08:46 PM For loop inside onload(); Adding events not working. :S
stewart's Avatar
Novice Talker

Posts: 11
Name: Stewart Howe
Location: New Orleans, LA (Picayune, MS)
Let me explain first....

on www.celermedia.com I have some projects listed and I am doing some js magic for each project. So I am attempting to just go through them all with a for loop and add their appropriate events (mouseover,out,click)...

Here is what currently am trying to do:

Code:
window.onload = function() {
    
    var projects = new Array();
        projects[0] = 'Tbr,http://www.theboardroomsurfandskate.com/';
        projects[1] = 'Gcs,http://www.gulfcoastshop.com/';
        projects[2] = 'Mts,http://www.mytutorialsite.com/';
        projects[3] = 'Mcp,http://www.mycustomportal.com/';
        projects[4] = 'Stew,http://stewart.celermedia.com/';

    for (i=0; i<projects.length; i++) {
        var projData = projects[i].split(',');
        var proj = document.getElementById('proj'+projData[0]);
            proj.onmouseover = function() { projectOn(projData[0]);  }
            proj.onmouseout     = function() { projectOff(projData[0]); }
            proj.onclick     = function() { go(projData[1]); }
    }
}
What I don't get is on the line...
var projData = projects[i].split(',');

If I change my 'i' variable to 0,1,2, etc... it works fine, for that ONE.. why would that work but not when I put in my i variable from my for loop ?


Thanks in advance !
__________________
stewart:howe
Web Developer & Programmer
www.CelerMedia.com
stewart is offline
Reply With Quote
View Public Profile Visit stewart's homepage!
 
When You Register, These Ads Go Away!
Old 01-24-2008, 04:21 AM Re: For loop inside onload(); Adding events not working. :S
chrishirst's Avatar
Super Moderator

Posts: 13,609
Location: Blackpool. UK
Cancel that I read the code incorrectly.


Need a URL to get ALL the code BTW
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System

Last edited by chrishirst : 01-24-2008 at 04:24 AM.
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-27-2008, 02:03 AM Re: For loop inside onload(); Adding events not working. :S
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
I test it, and works! I didnt test in IE 6, but...
You have a position error in your site with IE7: The footer div (copyright...) appears in the middle of the page on top of the content.
__________________
-----------------------
http://www.xumby.com
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Reply     « Reply to For loop inside onload(); Adding events not working. :S
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12217 seconds with 12 queries