Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > need help in displaying multiple arrays please

need help in displaying multiple arrays please
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2002
Status: Offline
Reply With Quote
Feb 28, 2003, 10:41 AM
 
here's my script

++++++++++++++++++++++++++++++++++++++++++++

if(document.images){
ftover = new Array(7);
ftout = new Array(7);
helpover = new Array(6);
helpout = new Array(6);
for(var n=1;n<=7;n++)

{
ftover[n]=new Image();
ftout[n]=new Image();
helpover[n]=new Image();
helpout[n]=new Image();
ftover[n].src="images/nav01_0"+n+"r.gif";
ftout[n].src="images/nav01_0"+n+"n.gif";
helpover[n].src="images/nav2_0"+n+"r.gif";
helpout[n].src="images/nav2_0"+n+"n.gif";
}
}



function tabOn(i) {
if(document.images)
document.images["ft"+i].src=ftover[i].src;
}

function tabOff(i) {
if(document.images)
document.images["ft"+i].src=ftout[i].src;
}

function helpOn(i) {
if(document.images)
document.images["help"+i].src=helpover[i].src;
}

function helpOff(i) {
if(document.images)
document.images["help"+i].src=helpout[i].src;
}

++++++++++++++++++++++++++++++++++++++++++++++

ftover and ftout has 7 items. the problem is that the helpover and helpout variable only has 6 but is still looking for a 7th item because there is only one for loop

for(var n=1;n<=7;n++)

since I am a javascript neophyte, i feel that i'm stuck in a rut. should i create a new for loop? if i do, would it affect my existing for loop? any help is appreciated. thanks.
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Feb 28, 2003, 11:06 AM
 
Just put an if conditional statement inside the for loop containing the helpover and helpout arrays like this:

for(var n=1;n<=7;n++)

{
ftover[n]=new Image();
ftout[n]=new Image();
ftover[n].src="images/nav01_0"+n+"r.gif";
ftout[n].src="images/nav01_0"+n+"n.gif";
if(n<7){
helpover[n]=new Image();
helpout[n]=new Image();
helpover[n].src="images/nav2_0"+n+"r.gif";
helpout[n].src="images/nav2_0"+n+"n.gif";
}
}
}

Also, doesn't creating an array(7) give you 0 - 6? If so, aren't you going past the end of both arrays? Sorry if I'm wrong here, I program in C++ for class a lot
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:50 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2