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).text();
var hours = parseInt(inputValue);
totalHours += (hours == null) ? 0 : hours;
});
I've tried $(this).val()
and $(this).html()
as well, but can't get the values out of the input fields.
Edit: Apologies, I knew I was forgetting to mention something. The "this." at the start of the each loop is because I am using backbone's models and collections. The first "this." refers to the specific model in question. It loops through the proper number of times, I just can't get the value.
Get rid of the
this.
before$(".timesheet-daily-input")
and use$(this).val()
to get the value of the inputs.Couldn't find an exact solution, but changed my approach by selecting the parent div, and looping through it's child elements.
It's hard to tell without more code but change
to
Note that
parseInt("09")
is0
and that the result of parseInt cannot benull
.