samedi 7 février 2015

jQuery getting sum with keypress always one step behind


Vote count:

0




I am trying to create an calculator in which I want add/sum on every key press I make like this:



$('#padd').keypress(function(){

var points = parseInt($(this).val());

console.log("Points: "+(points+parseInt(ypoints)));

});


My issue is that it seems like "points" always is one step behind. Lets say that my "ypoints" is 200 and I type in first 1, the console.log says "NaN"? If I then type in a "10" the console.log says "201" while in fact it should say "210"?!? If I then add an "100" in the add field it says "210" but it should say "300". Always one keypress behind?!?


What am I missing here or is this not the correct way to do this?


Any help is appreciated and thanks in advance :-)



asked 33 secs ago

Mansa

477






jQuery getting sum with keypress always one step behind

Aucun commentaire:

Enregistrer un commentaire