I am using javascript calculation. multiply 2 numbers: number 1 * number 2 = total
and how g-total but working only one value display?
I have need number 1 * number 2 = total and show Gtotal so please help and share a valuable idea...
HTML
<input
name="per_hour"
id="per_hour"
class="form-control"
value=""
onblur="perhour()"
placeholder="0"
/>
<input
name="per_hour_x"
id="per_hour_x"
class="form-control"
onblur="perhour()"
value=""
placeholder="0.00"
/>
Total
<input
name="per_hour_total"
id="per_hour_total"
class="form-control"
value=""
placeholder="0.00"
/>
G-Total
<input
type="text"
class="form-control total-fare"
id="total"
disabled
value="<?= $booking->total_fare ?>"
/>
<script>
function perhour() {
var per_hour = document.getElementById("per_hour").value;
var per_hour_x = document.getElementById("per_hour_x").value;
var amts = document.getElementById("total").value;
var totaperhour = Number(per_hour) * Number(per_hour_x);
var totalamt = Number(totaperhour) + Number(amts);
$("#per_hour_total").val(totaperhour).toFixed(2); //working
$("#total").val(totalamt).toFixed(2); //not working
}
</script>
It should be $('#per_hour_total').val(totaperhour.toFixed(2));
and not $('#per_hour_total').val(totaperhour).toFixed(2);
function perhour() { var per_hour = document.getElementById("per_hour").value; var per_hour_x = document.getElementById("per_hour_x").value; var amts = document.getElementById("total").value; var totaperhour = Number(per_hour) * Number(per_hour_x); var totalamt = Number(totaperhour) + Number(amts); $('#per_hour_total').val(totaperhour.toFixed(2)); $('#total').val(totalamt.toFixed(2)); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <div> total <input type="text" class="form-control total-fare" disabled id="total" value=""> </div> <div> per_hour <input name="per_hour" id="per_hour" class="form-control" value="" onblur="perhour()" placeholder="0"> </div> <div> per_hour_x <input name="per_hour_x" id="per_hour_x" class="form-control" onblur="perhour()" value="" placeholder="0.00"> </div> <div> per_hour_total <input name="per_hour_total" id="per_hour_total" class="form-control" value="" placeholder="0.00"> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.