0
Since I don’t know much about javascript I would like a little help to solve this problem of mine In this script below I have to do the calculation taking only the last digits separated by the hyphen -
value="10-banana-2,55" ==> só somar o ( 2,55 ) depois do segundo traço
id-nome-valor
$(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>
<form name="listForm" id="listForm">
<input type="checkbox" name="choice" value="10-banana-2,55" />2,55<br/>
<input type="checkbox" name="choice" value="12-uva-3,00" />3,00<br/>
<input type="checkbox" name="choice" value="13-pera-1,00" />1,00<br/>
<input type="checkbox" name="choice" value="16-tmate-2,00" />2,00<br/>
<input type="text" size="4" name="total" id="total" value="100,00" />
</form>