In my JavaScript code I am first calling a function to update an image:
document.getElementByID("i1").src = newImage;
then a few statements later the alert() function is called to display a message:
alert("image updated!");
However, when I run this code, what actually happens is that the alert box is popped up before the image is updated. When I click the "OK" button in the dialog to take the alert box down, the image updates.
Why is the order of these events not being preserved? And is there some kind of synchronizing function I can call to wait for the image update to complete before the alert dialog is displayed?
I'm open to restructuring the code in some ways (i.e., using something other than the alert() function), but I'd prefer a solution that allows the existing code to work as intended.