View Full Version : array driving me mad!

06-10-2004, 04:40 PM
This is driving me maaaaaaad and I dont know why it's not working!!

I set up an array when the page loads eg:

backup = new Array();
backup[0] = "testing";

then I have a function called undo() which tries to add a value to the array... only it cant be accessed. When I test the length of backup, it says it's ZERO... when you can clearly see I've put an item in it above!!

how come I cant access it? My functions are in an included .JS file maybe that's why?!

BTW: this is a modified version of axinya's undo-redo function which seems to work perfectly!! (http://www.codingforums.com/showthread.php?t=39987)

06-11-2004, 10:52 AM
you might need to declare it as global, like so:

var backup = new Array();

06-11-2004, 10:57 AM
Variables are automatically turned to global scope if the var keyword is not specified. Though it's a good practice to always put it.

homerUK, can you post more codes? Maybe you are re-initializing it somewhere.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum