This should be easy, but I can\'t seem to get it right.
var totalHours = 0;
this.$(\".timesheet-daily-input\").each( function () {
var inputValue = $(this).t
var inputValue = $(this).val();
It's hard to tell without more code but change
var inputValue = $(this).text();
var hours = parseInt(inputValue);
totalHours += (hours == null) ? 0 : hours;
to
var inputValue = $(this).val(); // use val
var hours = parseInt(inputValue, 10); // use 10 as radix
totalHours += isNaN(hours) ? 0 : hours; // compare to NaN instead of null
Note that parseInt("09") is 0 and that the result of parseInt cannot be null
.
Couldn't find an exact solution, but changed my approach by selecting the parent div, and looping through it's child elements.
var totalHours = 0;
this.$("#timesheet-daily-entry-fields-container").children().each(function () {
var inputValue = $(this).val();
var hours = parseInt(inputValue);
totalHours += isNaN(hours) ? 0 : hours;
});
Get rid of the this.
before $(".timesheet-daily-input")
and use $(this).val()
to get the value of the inputs.