i'm pretty new @ javascript. have variable , 2 buttons add or minus 1 variable, works; want make when variable = 0
minus button disables, variable wont go below 0.
<head> <script type="text/javascript"> var = 0; var add = function(valuetoadd) { += valuetoadd; document.getelementbyid('value').innerhtml = a; } </script> </head> <body> value:<span id="value">0</span> <button type="button" id = add onclick="javascript:add(1)">+</button> <button type="button" id = minus onclick="javascript:add(-1)">-</button> </body>
<head> <script type="text/javascript"> var = 0; var add = function(valuetoadd){ += valuetoadd; document.getelementbyid('value').innerhtml = a; if(a == 0) { document.getelementbyid('minus').disabled = true; } else { document.getelementbyid('minus').disabled = false; } } </script> </head> <body> value:<span id="value">0</span> <button type="button" id = add onclick="javascript:add(1)">+</button> <button type="button" id = minus onclick="javascript:add(-1)">-</button> </body>
Comments
Post a Comment