I can’t get this to work and I can’t think of any way to make this work,
I’m trying to have a button value change to a var every time you press it.
code-
<input onclick="change(this)" type="button" value="0" id="myButton1" />
<script>
value="1"
function change(this)
{
target.value = parseInt(target.value) + 1;
}
</script>
2
Answers
You need to declare the variable outside of the function. Here is the code with the fix.
You need to declare the variable outside the function and then increment it inside, otherwise you just reset it every time the function runs. I would also pass the event into the function so you can change the value of the clicked button rather than getting the element by id each time