user979587
user979587

Reputation: 265

has no method 'replace' jquery error

I got the following js code which is erroing in the console and i'm not too sure of what i'm doing wrong. Basically i'm trying to get a list of fields so i can do some calcs on.

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(function() {
    var labourItems;

    jQuery.each($('.labouritems'), function(key,value){
        labourItems.push(LabourItems.init(value));
    });

});

Console Error:

Uncaught TypeError: Object function () {
    var labourItems;

   jQuery.each($('.labouritems'), function(key,value){
       labourItems.push(LabourItems.init(value));
   });

} has no method 'replace'

Upvotes: 1

Views: 1990

Answers (1)

ColBeseder
ColBeseder

Reputation: 3669

live needs an event type eg. click.

it's treating the function as the event string and it's getting hella confused.

$('.hours').live(function() { /*... your code ...*/})    // wrong

needs to be:

$('.hours').live("click", function() { /*... your code ...*/})    // works

Upvotes: 5

Related Questions