1
I have the code below, and I need to add the values of the checkboxes instead of concatenating them. Can someone help me?
<!DOCTYPE html>
<html>
<head>
<style>
#out{width:350px;}
</style>
<script src="/scripts/snippet-javascript-console.min.js?v=1"></script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" name="dias[]" value="0.5">,5
<input type="checkbox" name="dias[]" value="1">1
<input type="checkbox" name="dias[]" value="0.25">,25
<input type="checkbox" name="dias[]" value="0.45">,45
<input type="checkbox" name="dias[]" value="0.5">,5
<input type="checkbox" name="dias[]" value="0.75">,75
<input type="checkbox" name="dias[]" value="0.8">,8
<br>
<input type="text" name="dias" value="" id="out">
<script type="text/javascript">
var inputs = $('input[name="dias[]"]');
inputs.on('change', function () {
var str = [];
var control = 0;
inputs.each(function () {
if (this.checked) {
str.push(this.value);
control++;
}
});
$('input[name="dias"]').val(str.join(', '));
console.log($('input[name="dias"]').val());
});
</script>
</body>
</html>
Where is the code in
php
?– mercador
this part of the code is an example that I found right here and adapted putting the values. The values come from the bank, in PHP... are additional for snacks (mashed potatoes, +cheese, pea, corn, etc...), and when marking the checkbox, I would like you to add the value of the additional to the price of the product and display on the same screen, without giving refresh. When you click on the "send order" button, I can add the sum and include the value (plus the additional ones) in the bank. but display on the same screen is being a problem.
– André Ponce
yes, sir! I already did, and forgive our failure! I started the question weighing on one thing, I ended up talking about another....
– André Ponce