I update three inputs in a row, they are updated sequentially via a single button click and I do a cool color change (glowing) effect to each input after completion of updating:
You should see something like this where t= time (i feel like a scientist)
[30.20] [20.32] [34.33] [Update] <--- Clicked this
t=1 Glow
t=2 Glows
t=3 Glows
but sometimes the color effect goes out of order like:
[30.20] [20.32] [34.33] [Update] <--- Clicked this
t=1 Glow
t=2 Glows
t=3 Glows
Here is my script:
FYI: i tested and found that the out of sequence issue begins on the .each
On the page they are one after the other.
function UpdatePrice(TheButton, Type) {
$(TheButton).parent().parent().find("input").each(function (index, element) {
$.ajax({
cache: false,
data: { ByContractID: $(element).parent().attr("id"), Cost: $(element).val(), ItemType: Type },
type: "Post",
url: '@Url.Action("UpdateCost")'
}).success(function () {
$(element).next().html(($(TheButton).parent().parent().children("td").eq(0).html() * $(element).val()).toFixed(2));
$(element).val(parseFloat($(element).val()).toFixed(2));
var old = $(element).css('background-color');
$(element).animate({ "background-color": "#D2F0C9" }, "fast", function () { $(element).animate({ "background-color": old }, "fast") });
});
});
return false;
}
What do y'all think?
Thanks!