0
I have a sales system, where the administrator marks the checkbox of the products that want to sell, soon after appears an input to enter the desired quantity, and at the end of the sale, is calculated the total value of all products with their certain quantities. All this is working perfectly.
But I wonder if there is a possibility that while the administrator is selecting the products and entering their quantities, an "Instantaneous calculation" was done in an input to know how much will be the final value.
I tried using a snippet but it didn’t work. I will put only the part of the code that interests me, along with the script that I already use to show and hide the input in front of each checkbox to not get too much information unnecessary, follow an example:
<style type="text/css">
input[type="number"] {
display: none;
}
</style>
<input type="checkbox" name="checkbox[]"> <input type="number" value="1" min="1" required="" max="10">
<input type="checkbox" name="checkbox[]"> <input type="number" value="1" min="1" required="" max="21">
<input type="checkbox" name="checkbox[]"> <input type="number" value="1" min="1" required="" max="13">
<script>
$('input[type="checkbox"]').on('click touchstart', function() {
if (this.checked) {
$(this).parent('td').find('input[type="number"]').show();
} else {
$(this).parent('td').find('input[type="number"]').hide();
}
});
</script>
These checkboxes are within a table. For example, if it is 8 products, it will be 8 checkbox, and as it is within a table, I need to multiply the price of the product (I would put a $Row['price']]), by the amount entered in the input (that belongs to this product), and then add it all up. But in this way that you did, I think there would be no way, because this script would be at the bottom of the right page? and not inside the table. I’m sorry I didn’t mention this before, but I was very confused at the time of asking this question
– Afuro Terumi
"because this script would be at the end of the right page?" It doesn’t really matter where the script is going to be, it only needs to run after the page is loaded to find the checkbox. As to multiply the price just take the value, remember that in this case the
$(this).next("input")
takes the next input without any other condition, if you have a value and quantity input, assign names or classes to them, to facilitate and find. For example if one has the class "Qtde" and another "value", it can do so$(this).next("input.qtd")
:)– Ricardo Pontual
It worked out here, buddy, hug!
– Afuro Terumi