The programming languages use international numbering system, there is no commas is point to be able to do mathematical operations
Without running away from your code, just formatting the numbers to be able to do mathematical operations.
$(function(){
total = document.getElementById('total');
$(document.getElementsByName('choice')).bind('click',function(){
var valTotal = total.value;
valTotal = parseFloat(valTotal.replace(',','.'));
var valInput = (this.value);
valInput = parseFloat(valInput.replace(',','.'));
var novoTotal=0;
total.value = (this.checked) ? parseFloat(( valTotal + valInput )) : parseFloat(( valTotal - valInput )) ;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><formname="listForm" id="listForm">
<input type="checkbox" name="choice" value="2,55" />2,55<br/>
<input type="checkbox" name="choice" value="2,00" />2,00<br/>
<input type="text" size="6" name="total" id="total" value="100,00"/>
</form>
If you want the total to always have 2 decimal places in total.value
use the toFixed
$(function(){
total = document.getElementById('total');
$(document.getElementsByName('choice')).bind('click',function(){
var valTotal = total.value;
valTotal = parseFloat(valTotal.replace(',','.'));
var valInput = (this.value);
valInput = parseFloat(valInput.replace(',','.'));
var novoTotal=0;
total.value = (this.checked) ? parseFloat(( valTotal + valInput )).toFixed(2) : parseFloat(( valTotal - valInput )).toFixed(2) ;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><formname="listForm" id="listForm">
<input type="checkbox" name="choice" value="2,55" />2,55<br/>
<input type="checkbox" name="choice" value="2,45" />2,45<br/>
<input type="checkbox" name="choice" value="2,50" />2,50<br/>
<input type="checkbox" name="choice" value="2,00" />2,00<br/>
<input type="text" size="4" name="total" id="total" value="100,00"/>
</form>
To return the total with a comma.
$(function() {
total = document.getElementById('total');
$(document.getElementsByName('choice')).bind('click', function() {
var valTotal = total.value;
valTotal = parseFloat(valTotal.replace(',', '.'));
var valInput = (this.value);
valInput = parseFloat(valInput.replace(',', '.'));
var novoTotal = 0;
var value = (this.checked) ? parseFloat((valTotal + valInput)).toFixed(2) : parseFloat((valTotal - valInput)).toFixed(2);
total.value = value.replace('.', ',');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><formname="listForm" id="listForm">
<input type="checkbox" name="choice" value="2,55" />2,55<br/>
<input type="checkbox" name="choice" value="2,45" />2,45<br/>
<input type="checkbox" name="choice" value="2,50" />2,50<br/>
<input type="checkbox" name="choice" value="2,00" />2,00<br/>
<input type="text" size="4" name="total" id="total" value="100,00" />
</form>
DOCS:
replace
parseFloat