I have a JavaScript function that is quite long and performs a number of tasks, I would like to report the progress to the user by updating the contents of the SPAN element with a message when I go. I tried adding document.getElementById ('spnProgress'). InnerText = ... statements in all functional code.
However, while the function executes the user interface, it will not be updated, so you will always see the last message recorded in the SPAN, which is not very useful.
My current solution is to break the task down into several functions, at the end of each of them I set the SPAN message and then “run” the next one with window.setTimeout with a very short delay (say 10 ms). This gives control and allows the browser to redraw the SPAN with the updated message before starting the next step.
However, I find it very dirty and hard to follow the code, I think there should be a better way. Anyone have any suggestions? Is there a way to force the SPAN to redraw without leaving the function context?
thanks
javascript repaint progress
Lambypie
source share