ctoz Posted August 22, 2007 Share Posted August 22, 2007 This changes display and color sucessively for the items in the array:function boxDC (display,color,current) {oneWhite = new Array("h01","h03","h05","h09");box = document.getElementById(oneWhite[current]);box.style.display = display;box.style.color = color;if (current != oneWhite.length - 1) {current++;setTimeout("boxDC('" + display + "','" + color + "'," + [current] + ")",60);}}How to extend this function so that on different occasions it can be used with different arrays? Something like...oneWhite = new Array("h01","h03","h05","h09");oneRed = new Array("h02","h04","h06","h07");oneGreen = new Array("h01","h02","h08","h09");function boxDC (array, display,color,current) {box = document.getElementById(arrayname[current]);box.style.display = display;box.style.color = color;if (current != oneWhite.length - 1) {current++;setTimeout("boxDC('"+ array"','" + display + "','" + color + "'," + [current] + ")",60);}}positively the last question about this function !cheers. Link to comment Share on other sites More sharing options...
jesh Posted August 22, 2007 Share Posted August 22, 2007 I think your function is pretty close to working.If you had those three arrays: oneWhite = new Array("h01","h03","h05","h09");oneRed = new Array("h02","h04","h06","h07");oneGreen = new Array("h01","h02","h08","h09"); And you passed one of those arrays as an argument to the function: boxDC(oneGreen, 'block', '#ff8c00', 2); Then in your function, you could do something like this: function boxDC(array, display, color, current){ box = document.getElementById(array[current]); box.style.display = display; box.style.color = color; if (current != array.length - 1) { current++; setTimeout("boxDC('"+ array"','" + display + "','" + color + "'," + current + ")",60); }} Notice that if you call your parameter "array" in the function definition, and the parameter that you pass that function is, in fact, an array, you can simply use that name as if it were the array itself.Example: var AnArray = new Array(1,2,3,4,5);function Test(SomeArray){ alert("There are " + SomeArray.length + " elements in that array.");}Test(AnArray); Link to comment Share on other sites More sharing options...
ctoz Posted August 22, 2007 Author Share Posted August 22, 2007 3am here, I woke thinking, "too simple, it'll probably need an array of the arrays and pop()..." Many Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.