I’ve got two events: an onFocus (saveOld) and an OnChange (showPoints). When a user focuses in the drop down I use the jquery.data function to save the old value of the drop down. When the user changes the value of the drop down I check to see if the old value was larger then then the current value. If so, I adjust the total accordingly. But this only works when I alert the old value after getting it from the .data function in my onChange. Without the alert nothing happens.
function showPoints(pointCategory, ddlAmount, name){
old = jQuery.data(document.body,name);
alert(old);
var Points = parseInt($('p#points').html());
if(old > ddlAmount){
diff = old - ddlAmount;
currentPoints = Points + (diff * pointCategory);
}else{
currentPoints = Points - (ddlAmount * pointCategory);
}
$('p#points').html(currentPoints);
}//showPoints
function saveOld(oldAmount, name){
$(document.body).data(name,oldAmount);
}
Without the alert in showPoints() this does not work correctly. What is going wrong?
EDIT: Note that I have already tried a this.delay(1000) where the alert should be. Still did not work.
Try changing onfocus to onclick and also save your current value to .data in the end of showPoints like so:
I would use local variables inside showPoints function.