View Full Version : array driving me mad!

06-10-2004, 03: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, 09:52 AM
you might need to declare it as global, like so:

var backup = new Array();

06-11-2004, 09: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.