Reputation: 395
I have some JavaScript code:
var update_money = function(money_am){
var d = {'ammount': money_am};
$.post("/adr/", d, load_money)
}
z = parseFloat($('#money').val());
$('#money').change(z, update_money);
When it executes, it gives me a runtime error:
TypeError: 'stopPropagation' called on an object that does not implement interface Event.
In debug, I found that money_am
is not a float. It is an object. But if I change my code like this:
var update_money = function(money_am){
var d = {'ammount': parseFloat($('#money').val())};
$.post("/adr/", d, load_money)
}
It works great. What should I do to fix this problem?
Upvotes: 3
Views: 883
Reputation: 5178
Data, that was passed to event handler, can be accessed by event.data
:
var update_money = function(event)
{
var money_am = event.data;
alert(money_am);
var d = {'ammount': money_am};
$.post("/adr/", d, load_money);
}
function load_money() { }
z = parseFloat($('#money').val());
$('#money').change(z, update_money);
Upvotes: 2
Reputation: 1438
Make sure that the money-value is parseable by parseFloat:
You also might want to change your code to this:
$('#money').change(function() {
var z = parseFloat($('#money').val());
load_money(z);
});
This will allow you to get the new money value everytime #money-field is changed. Instead of always using the same value. Along with properly defining z.
Upvotes: 0