Auto update textTotal fields
Dear all,
I am just a beginner programmer of jquery that still studying.
I have a form and it contains these fields.
textPrincipal
textInterest
textServiceCharge
textTotal
my scenario is.
when I input 1000 to my textPrincipal, my textTotal will automatically update to 1000 without going or clicking to other fields. and when I input 10 in textInterest automatically the value of textTotal field will change to 1100 because 10 percent of 1000 is 100. the same thing in textServiceCharge when I input 50, my textTotal will change to 1150.
I have a code but its not what i want to happen.
I hope you get exactly what i want to say. sorry for my bad english.
Details can be found here: http://jsfiddle.net/9BPCU/5/
$(document.body).on('change', 'input[name]', function() { var form = document.forms['calculator'], prin = parseFloat(form.principal.value), intr = parseFloat(1 + form.interest.value), serv = parseFloat(form.service.value); $('[name=total]').val(prin * intr + serv); }); $(function () { // manually trigger the change event to display // the total using the default values $(document.forms['calculator'].principal).change(); })