I'm really confused, and not even sure what to search for to find answers. I'm getting multiple calls to a javascript function. I'ts not making sense to me.
Here's what the code does.
$('expenses_txt').live(\'keyup\', function() {
$(this).typeWatch({ highlight: true, wait: 500, captureLength: 0, callback: calculate_expenses });
});
The "Calculate_expenses" is a javascript function that uses jquery ajax to call a php page that returns data that gets displayed in a span.
I'm using firebug to help me debug and in the Calculate_expenses function I put a "console.log" to debug when this function is being called.
Here's whats going on. I only have 1 input box in the DOM at the time this happens, when I press only one key, the output in the console puts out one debug msg like it should, when I press a key again in the same input box the output in the console is doubled (ie, the Calculate_expenses function got called twice but should have only been called once), when I press a key again (for a total of 3 key presses) the output in the console puts out 3 calls to the Calculate_expenses function now.....and so forth. I don't really know what's going on here. The code appears to me that it would only call the Calculate_expenses function 1 time, but when using firebug it actually is being called over and over when I don't want it to be.
Any ideas? Is it the way I'm using .live() If I just use the "keyup" event it works fine, problem is I need to use typeWatch plugin to delay the ajax call until after the typing is finished and the keyup event triggers too soon. The reason I'm using live() is because I dynamically add elements to the dom and this is the only way I could figure out how to use both typeWatch and dynamically add elements to the dom that needed to be summed up...
your thoughts are appreciated. thanks.