I have this code which works fine for adding up input boxes.
$.fn.sumValues = function() {
var sum = 0;
this.each(function() {
if ( $(this).is(':input') ) {
var val = $(this).val();
} else {
var val = $(this).text();
}
sum += parseFloat( ('0' + val).replace(/[^0-9-\.]/g, ''), 10 );
sum = Math.round(sum*Math.pow(10,2))/Math.pow(10,2);
});
return sum;
};
$(document).ready(function() {
$('input.money1').bind('keyup', function() {
$('#totalsales').html( $('input.money1').sumValues() );
});
});
However I want to have seperate boxes for pound/pence (money1 for the pound boxes and money2 for pence). I have tried adding
$('input.money2').bind('keyup', function() {
$('#totalsales2').html( $('input.money2').sumValues() );
});
But as you can tell this will add them up other 100, is there anyway I can make it add 1 to totalsales for every one hundred?
JSFiddle – http://jsfiddle.net/RZrTa/
Would be better off with a jsfiddle as im not 100% sure what you mean. If can can set up an example it would help get your answer.
But if all you want to do is take the pence value and for every 100 pence add 1 to the pounds then something like