Come on, the first thing I modified in your code were the inputs to facilitate the result see:
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
I added the type to checkbox and changed the comma to dot
Now for you to use the variables in PHP as $variable, $total and $total_general you will need to save the data after each change in the checkbox, you can use ajax for this.
<?
$variavel = 100,00
?>
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
<input type="checkbox" checked="" value="20.00" />
<div id='resultado_soma'><?echo $total?></div> <!--Resultado da soma dos checkbox-->
<div id='resultado_soma_menos_variavel'><?echo $total_geral?></div>
<!-- Resultado Pegando a Variavel - Resultado checkbox -->
Now javascript for all this work
(function() {
var elements = document.getElementsByTagName('input');
var resultado = document.getElementById('resultado_soma');
var total = 100.00;
for (var i = 0; i < elements.length; i++) {
elements[i].onclick = function() {
if (this.checked === false) {
total = total - this.value;
} else {
total = total + parseFloat(this.value);
}
resultado.innerHTML = total;
}
}})();
You can see the full code here too : https://jsfiddle.net/kcnhr66w/1/
Friend, You need to name the input’s, So they can be assigned to functions in javascript, If everyone has not assigned ID’s, It is not possible to do the sum. For example: <input type="" checked="" value="20,00" id="val1" />
– Mega