Anyone know how to clear an array using the onclick function?
Every time I hit a "submit" button, items are saved into an empty array called boxes and displayed on the screen. In order to clear the items from the screen, i hit the "clear button, the items clear from the screen, but not from the array.
I have a function named "clear" where i delete the items from the screen and
i've tried using boxes.length = 0 or Array.clear(boxes) = []; and those didn't work (notice i use those inside the function named "clear"
Try clicking the submit button, then click on a box and check out the id number. After that, hit the clear button, all boxes should clear.
Hit the submit button and click on a box again and check out the id number. It's supposed to start over from zero, but instead the id number keeps going from the previous.
Every time the clear button is hit, the array should be cleared.
//Clears the boxes
function clear() {
var sceneDivs = document.querySelectorAll("div#scene div");
for (var i = 0; i < sceneDivs.length; i++) {
var scene = document.getElementById("scene");
var clear = document.getElementsByTagName("div")[1];
scene.removeChild(clear);
}
boxes.length = 0;
counter = 0; // or = 1;
}
Try clicking the submit button, then click on a box and check out the id number. After that, hit the clear button, all boxes should clear.
Hit the submit button and click on a box again and check out the id number. It's supposed to start over from zero, but instead the id number keeps going from the previous.
Every time the clear button is hit, the array should be cleared.
You know what I mean?
Originally Posted by pholder
Thank you for your response,
I tried both of those and they didn't work.
Following your directions from the earlier post, I don't see the problem.
The ID values do seem to reset to 0 in my testing.
I just visited the above URL in IE8 and IE9. No Boxes were shown.
Your JavaScript contains some statements such as
Code:
console.log(counter);
It seems console.log is not supported in IE (error message: "console" is not defined).
I tried to comment those statements out. Then Boxes could be created and cleared in IE9 - just as in Firefox and Chrome.
Bookmarks