3

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?

4
  • What's the value of load_money? Commented Sep 16, 2014 at 12:17
  • Did you declare z as a variable earlier in the code, forgetting to declare var can give wierd behaviour? Commented Sep 16, 2014 at 12:20
  • @Paradoxis load_money is another function. I think it doesn't matter, becouse actually I have error before post. When update_money executed money_am has wrong type, and thats actually problem. Commented Sep 16, 2014 at 12:26
  • @Adrian-Forsius I didn't declare z as a variable earlier. Actually I try it now, but it didn't work too, and gives me same error. Commented Sep 16, 2014 at 12:30

2 Answers 2

2

Data, that was passed to event handler, can be accessed by event.data:

Fiddle.

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.