you need to move the string var x = 0;somewhere outside the function countso that it is in the global scope. This means that the changes made to it by the function countwill be saved.
eg.
var x = 0;
function count() {
x += 1;
document.getElementById( "counting" ).value = x;
}
source
share