I tried to write a script that increments a variable value, every time a button is clicked.
<script type="text/javascript">
// if the count variable is undefined, set its value to zero
if(! count) {
var count = 0;
}
// function to increment value of count variable
incrementCount() {
count++;
}
</script>
<!-- button to call incrementCount() function, on click -->
<form>
<input type="button" value="Count" onclick="incrementCount()">
</form>
<br />
<script type="text/javascript">
// output count variable
document.write(count);
</script>
Unfortunately the script is not working. Could you please tell me why?
Seriously though, that’s fine!
JavaScript really is the way to go for this functionality and I’m more than happy to explain things to you at whatever level you need.