Penjumlahan menggunakan checkbox

Membuat penjumlahan dengan menggunakan checkbox dan JS

/* ======
  Script 
=========*/ 

$(document).on("click", "input[type='checkbox']", function(){
    total=0;
    $("input[type='checkbox']:checked").each(function(){
        total += parseInt($(this).val())
    })
    $("input[name='total']").val(total)
})

/* ====== 
   HTML
=========*/

<label><input type="checkbox" value="2000" /> Nasi 2000</label><br>
<label><input type="checkbox" value="2200" /> Nasi 2200</label><br>
<label><input type="checkbox" value="2400" /> Nasi 2400</label><br>
<label><input type="checkbox" value="2500" /> Nasi 2500</label><br>
<br>
<input name="total" />

About Author

Gilang Sonar Amanu

Do It Do It Do It


Comment & Discussions

    Please LOGIN before if you want to give the comment.