Very simple ...
You have set the value of a = 0;
and var b = a == 0;
. At this time a will have the value of 0 and b will have the value of true. What shows the first values in inputs
.
After clicking the button, you are updating the value of to for a + 1
. However, you are not updating the value of b , because when you click the button, it calls the function aoba()
, and only runs that code below:
function aoba(){
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
That is, at no time is the value of the variable b being updated.
To update the b value, put it inside the aoba()
function, like this:
function aoba(){
var b = a == 0;
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
So the value of b will be updated as desired. The result can be seen in the code below:
var a = 0;
function aoba(){
var b = a == 0;
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
<button id="a" value="b" onclick="aoba()" name="botão">I'm gonna crazy.</button>
<p>
<input type="text" id="zbox">
</p>
<input type="text" id="ybox">
Enjoying, this list of questions offers great content to your doubt, directly or indirectly.