Ok so as you can see in the code snip bellow I am creating choices (inputs) in number (1) in number (2) I display the choice's name and in number (3) I display the unit price.
(1) is a number from 1 to n, I want to take the input number from each (1) and multiply it with the unit price (3) (example x=(1)*(3)) and then sum all of these results and display them in another textbox. I have tried several things but I couldn't make it happen.
I could really use some guidance here.
Any more information I will be happy to provide.
<?php
$sum = $choice['qty'] * $choice['timi'];
foreach($choice3 as $choice3){
?>
//(1)
<input type="number" class="colorqty" name="color[<?php echo $i; ?>][unit]" step="<?php echo $step; ?>" value="0" min="0" class="color_qty_1" onchange="updateTotal();">
//(2)
<input type="text" value="<?php echo $choice3['price_name']; ?>" name="color[<?php echo $i; ?>][price_name]" readonly="readonly" class="color_qty_2">
//(3)
<input type="text" value="<?php echo $choice3['price']."€"; ?>" name="xrwmas" readonly="readonly" class="color_qty_2" id="tests"> <br />
<?php $i++; } ?>
for example from the loop above we get
I want to multiply in this example 5 * 68, 0 * 74, etc and then sum the results and display it in the sum box.
@Jerson is close but I it gets really messed up this is a bit of an edit on his code but still can't figure it out.
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="58" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="33" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="54" readonly="readonly" class="color_qty_3" id="price">
<br>
<input type="number" style="width:40px" class="colorqty" id="input_value" step="1" value="0" min="0" onchange="updateSum();">
<input type="text" value="55" readonly="readonly" class="color_qty_3" id="price">
<br>
<br><br>
<label for="sinolo" class="color_qty_2" style="margin-left:45px"> Σύνολο €</label>
<input type="number" class="color_qty_2" style="background-color:white;color:black;width: 90px; border-color:black;border-radius:5px; border-width:1px; text-align:center;" value="<?php echo number_format((float)$sum, 2, '.', ''); ?>" id="a3" readonly="readonly">
and the js
function updateSum(value,id) {
var elements = document.getElementsByTagName('input')
var input_val = 0;
var price_val = 0;
var some_test = 0;
var test1 = 0;
for(let i = 0 ; i < elements.length; i++) {
if(elements[i].getAttribute('id') == 'price') {
price_val = parseInt(elements[i].value)
}
if(elements[i].getAttribute('id') == 'input_value') {
input_val = parseInt(elements[i].value)
}
test1 = price_val*input_val;
some_test += test1;
document.getElementById('a3').value = some_test
}
}
