sumar uno

sumar uno con javascript

by femfoyou

HTML

<form name=formulario>
<input name="checkbox" type="checkbox" onclick="if (this.checked) sumar(1); else restar(1)" value="checkbox">$1<br>
<input name="checkbox" type="checkbox" onclick="if (this.checked) sumar(2); else restar(2)" value="checkbox">$2<br>
<input type="text" name="total" value="0">
</form>

    <script>
    function inc_count(){
        res = document.getElementById("output");
        res.value = parseInt(res.value)+1;
    }
    </script>
     
    <input type="text" value="4" id="output"/>
    <a href="javascript:inc_count();">Incrementar</a>

JavaScript

var total=0;

function sumar(valor) {
total += valor;
document.formulario.total.value=total;
}

function restar(valor) {
total-=valor;
document.formulario.total.value=total;
}