Hey all,
I'm fairly new to jQuery still and am trying to pick up ways to help optimize my code. I'm currently working on an application in which I'm calling some calculation methods everytime someone leaves a field (.blur). I only want to call these methods when certain criteria are met (such as value != 0). I have 9 fields where I'm calculating and checking currently.
$(document).ready(function () {
var currentValue = {};
$("#txtValue1").focus(function () {
currentValue = $(this).val();
}
).blur(function () {
$("#txtValue1").valid();
if (currentValue != $("#txtValue1").val() && $("#txtValue1").val() != "") {
CallCalculations();
}
});
$("#txtValue2").focus(function () {
currentValue = $(this).val();
}
).blur(function () {
$("#txtValue2").valid();
if (currentValue != $("#txtValue2").val() && $("#txtValue2").val() != "") {
CallCalculations();
}
});
});
function CallCalculations() {
// Do Stuff
};
I know it's possible to condense these functions down into one more generic one (using a CSS class as a selector instead of an ID) but I just can't seem to figure it out as I'm still new to jQuery / Javascript in general. Any help would be greatly appreciated. Thank you!