i'd like to ask how to do arithmatic using javascript Here i have some input value
<div class="form-group">
<label for="exampleInputTotalBayar">Total Bayar</label>
<input type="text" class="form-control" id="inputTotalBayar" placeholder="Total Bayar" name="totalBayar" value="{{ $peminjaman->totalBayar }}">
</div>
<div class="form-group">
<label for="exampleInputJumlahBayar">Telah Membayar</label>
<input type="text" class="form-control" id="inputJumlahBayar" onchange="" placeholder="Jumlah Bayar" name="jumlahBayar" value="{{ $peminjaman->jml_bayar }}">
</div>
I have this input too
<div class="form-group">
<label for="exampleInputDenda">Denda</label>
<input type="text" class="form-control" id="exampleInputDenda" placeholder="Denda" name="denda" value="{{ $peminjaman->denda }}">
</div>
And this
<div class="form-group">
<label for="exampleInputBayarKembali">Jumlah Bayar Pengembalian</label>
<input type="text" class="form-control" id="inputBayarKembali" onchange="" placeholder="Bayar Pengembalian" name="bayarPengembalian">
</div>
And using javascript, the answer from arithmatic operation will be shown here
<p>Bayar Pengembalian: <div id="bayar" name="bayar"></div></p>
<p>Sisa: <div id="sisa" name="sisa"></div></p>
For Bayar Pengembalian, it work just fine. But when im trying to calculate Sisa, the answer wont be shown. Here is my javascript
$("#exampleInputDenda").change(function() {
var bayar = parseInt("0");
var totalBayar = parseInt($("#inputTotalBayar").val());
var jumlahBayar = parseInt($("#inputJumlahBayar").val());
var denda = parseInt($("#exampleInputDenda").val());
bayar = bayar + denda + totalBayar - jumlahBayar;
$("#bayar").html(bayar);
});
$("#inputBayarKembali").change(function() {
var sisa = parseInt("0");
var bayar = $("#bayar").val();
sisa = sisa + $("#inputBayarKembali").val()-bayar;
$("#sisa").html(sisa);
});
would you help me with my problem? I'm just in the middle of studying javascript and laravel, so i really need your help... thanks before