javascript - Change Total with a click of the button -


<button id "add" onclick="changetotal()">change total add 5</button> <button id "subtract" onclick="changetotal()">change total subtract 5</button>   var total = 10;  function changetotal () {  if (add === true) {     total = total + 5; } else (subtract === true) {  total = total - 5; }; 

i not sure how heck accomplish this...newbie...but want have 2 buttons. 1 adds total in

...and button subtracts total in

. need ongoing...like not stop @ number -negative or +positive. all!

i tried screwing around newly learned knowledge of innerhtml...

<p>click button display date.</p>  <button onclick="displaytotal()">the time is?</button>  <script> function displaytotal() {     var x = 5;    var p = document.getelementbyid("demo").innerhtml = x;    var y = document.getelementbyid("demo").innerhtml = + 5;   } </script>  <p id="demo"></p> 

i assuming want div increment every time click button, rather continuously increment after 1 click.

<p>click button display date.</p>  <button onclick="displaytotal();">the time is?</button>  <script> function displaytotal() {    var p = document.getelementbyid("demo").innerhtml;    document.getelementbyid("demo").innerhtml = parseint(p, 10) + 5; } </script>  <p id="demo">0</p> 

if want 2 buttons increment or decrement, can parameterize function.

<p>click button display date.</p>  <button onclick="increment(5);">increment</button> <button onclick="increment(-5);">decrement</button>  <script> function increment(val) {    var p = document.getelementbyid("demo").innerhtml;    document.getelementbyid("demo").innerhtml = parseint(p, 10) + val; } </script>  <p id="demo">0</p> 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -