JSFiddle - React, Tailwind, and code Playground

by Dedi Wibisono

HTML

<input type="checkbox" name="channelcost" value="10" onClick="test(this);"  />10<br />
    <input type="checkbox" name="channelcost" value="20" onClick="test(this);" />20 <br />
    <input type="checkbox" name="channelcost" value="40" onClick="test(this);" />40 <br />
    <input type="checkbox" name="channelcost" value="60" onClick="test(this);" />60 <br />
    
    Total Amount : <span id="Totalcost"> </span>

JavaScript

var total = 0;

    function test(item){
        if(item.checked){
           total+= parseInt(item.value);
        }else{
           total-= parseInt(item.value);
        }
        //alert(total);
        document.getElementById('Totalcost').innerHTML = total + " /-";
    }