say that my array value is as follows. var array = [1, 2, 3, 4, 5, 6, ...] how can I make it so that clicking the button can display the item in array one after another in different boxes?
for example..first click = array[0] second click = array[1] ...and so on.
below is my code so far. every time the button is clicked, it will only print all the values in array one by one to the same table.
<tr>
<td><p id="result2"></p></td>
<td><p id="result3"></p></td>
....
</tr>
<button onclick="clickBowl()">Bowl</button>
JS:
var k = 0;
function clickBowl() {
x = document.getElementById("result2").innerHTML = frameArr[k++];
}
Try this:
HTML:
JS:
That way, you define a global scope var
i
that each time you click on the bowl, you will add one after you use it in order to get the value with that key from your array and append atd
child to your results row.