thank you in advance for your help.
I was wondering how can I do to display the total rounded up in case of odd number.
Thanks
Here is the code:
$(document).ready(function() {
$('.variable-field').on("input", function() {
var $row = $(this).closest('tr');
var qty = $row.find('.quantity').val() || 0;
$row.find('.totalcostprice').val(qty / 3);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-striped table-bordered proposal-table" id="proposal-table">
<thead>
<tr>
<th>Quantity</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="number" class="form-control variable-field quantity" name="Quantity" /></td>
<td><input type="number" class="form-control width-80 totalcostprice" name="TotalCostPrice" readonly /></td>
</tr>
</tbody>
</table>
>Solution :
You can use Math.ceil()
. Try this
$(document).ready(function() {
$('.variable-field').on("input", function() {
var $row = $(this).closest('tr');
var qty = $row.find('.quantity').val() || 0;
$row.find('.totalcostprice').val(Math.ceil(qty / 3));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-striped table-bordered proposal-table" id="proposal-table">
<thead>
<tr>
<th>Quantity</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="number" class="form-control variable-field quantity" name="Quantity" /></td>
<td><input type="number" class="form-control width-80 totalcostprice" name="TotalCostPrice" readonly /></td>
</tr>
</tbody>
</table>