Thanks for helping me get a calculator function put together for my little app.
One problem, however. While it works swimmingly on static html, it tanks hard on the Repeater fields.
I can enter numbers in the first field and it shows up in the Sum field just fine. But if I add a field, nothing I type activates the calculate function, which is looking for a keyup. Only when I go back into the original field and hit any key does it re-calculate all available fields. So, the Javascript can see the numbers in the input fields, but it does not recognize the events. Any ideas? How can I alter the following code so it works with an onkeyup="calculateSum();" inserted in the code of each input? It doesn't work as is, likely because of the JQuery dom event. I also want it to work whenever the Remove Field button is clicked too. I presume the same sort of thing - an onclick="calculateSum();" entered into the code of the button. Just not advanced enough in Javascript to riddle this out.
One problem, however. While it works swimmingly on static html, it tanks hard on the Repeater fields.
I can enter numbers in the first field and it shows up in the Sum field just fine. But if I add a field, nothing I type activates the calculate function, which is looking for a keyup. Only when I go back into the original field and hit any key does it re-calculate all available fields. So, the Javascript can see the numbers in the input fields, but it does not recognize the events. Any ideas? How can I alter the following code so it works with an onkeyup="calculateSum();" inserted in the code of each input? It doesn't work as is, likely because of the JQuery dom event. I also want it to work whenever the Remove Field button is clicked too. I presume the same sort of thing - an onclick="calculateSum();" entered into the code of the button. Just not advanced enough in Javascript to riddle this out.
function calculateSum() {
var sum = 0;
jQuery('input[class^="checkadd"]').each(function() {
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat($(this).val());
}
});
jQuery('input[name="totalSum"]').val(sum);
}
jQuery('.checkadd').on('keyup', function() {
calculateSum();
});