Reputation: 265
i have the below code:
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
var rate = $(object).children('.rate').first();
var hours =$(object).children('.hours').first();
total = rate * hours;
updateTotal(object,total);
},
updateTotal: function(object, total) {
$(object).children('.total').first().attr('value', total)
}
}
//reactTochange for those inputs that you want to observe
$('.hours').live("click", function() {
jQuery.each($('.labouritems'), function(key,value){
LabourItems.init(value);
});
});
and geting an undefined function error:
updateTotal(object, total) is undefined
Could you please let me know what i'm doing wrong.
Upvotes: 0
Views: 237
Reputation: 25145
updateTotal
is a function in LabourItems
so call
LabourItems.updateTotal(object,total);
or ( only when invoked from any other function of LabourItems
or instances of it)
this.updateTotal(object,total);
UPDATE :
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
var rate = $(object).children('.rate').first();
var hours =$(object).children('.hours').first();
this.total = rate * hours;
this.updateTotal(object);
},
updateTotal: function(object) {
$(object).children('.total').first().attr('value', this.total)
}
}
//reactTochange for those inputs that you want to observe
$('.hours').live("click", function() {
jQuery.each($('.labouritems'), function(key,value){
LabourItems.init(value);
});
});
Upvotes: 8