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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Arrays!

Status
Not open for further replies.

TheAtomic

Technical User
Oct 18, 2004
9
GB
Basically I have two 'sets' of rollover images on a a page. The first example is on everypage, but the second changes depending on what page you are on.

When I had just the one set the rollover worked fine, but now I introduced the second set, the rollovers are just referring to the second example below.

I guess its a problem with addressing the array and the second array is overwriting the first?

Any Ideas?

Code:
var menus = new Array('home','env','admim', 'research', 'business', 'services', 'people', 'intranet', 'vacancies', 'contactus');

var i;
var imgs = new Array(menus.length);
for (i = 0; i < menus.length; i++) {
imgs[i] = new Image();
imgs[i].src = 'buttons/topmenu_' + menus[i] + '_mo.gif';
}

function mm(obj, i) {
obj.ori = obj.src;
obj.src = imgs[i].src;
}

function mm2(obj) {
obj.src = obj.ori;
}
Code:
var menuspeople = new Array('a2z', 'faculty', 'resstaff', 'postgrad', 'adminstaff', 'technicians');

var i;
var imgs = new Array(menuspeople.length);
for (i = 0; i < menuspeople.length; i++) {
imgs[i] = new Image();
imgs[i].src = '/env/_henry/buttons/people_' + menuspeople[i] + '_mo.gif';
}

function mmpeople(obj, i) {
obj.ori = obj.src;
obj.src = imgs[i].src;
}

function mmpeople2(obj) {
obj.src = obj.ori;
}
 
Yes - the problem is that you're overwriting your "imgs" array with the second lot of data.

One (of many) ways around this would be simply to rename the "imgs" array for the second lot of code.

Hope this helps,
Dan
 
Yes, your imgs array is being overwritten. You can rename one of the arrays, or use:

function mm(obj, i) {
obj.ori = obj.src;
obj.src = 'buttons/topmenu_' + menus + '_mo.gif';
}

for your primary rollover code, and:

function mmpeople(obj, i)
{
obj.ori = obj.src;
obj.src = '/env/_henry/buttons/people_' + menuspeople + '_mo.gif';
}

for your secondary rollover code.

Lee
 
Cheers :)

Cant believe I missed the imgs Array!

Doh!
 
If you use the function modifications that I wrote, it doesn't matter if you overwrite the imgs array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top