Animated in-progress indicator for long running pages

On pages that take more than a few seconds to complete, its a good idea to show some type of in-progress meter. Things like bulk email processing and large file uploads are good candidates. Often this doesn’t need to be as complicated as a real progress meter, where you show the actual percentage complete. Instead, an “in progress” meter just gives feedback to the user to let them know that something is going on.

I usually place a hidden element on the page, then use JavaScript to make it appear when the form is submitted. Something like:

<p style="visibility:hidden" id="inprogress">
    <img id="inprogress_img" src="progress.gif">
    Please Wait...
</p>

<input type="submit" onclick="document.getElementById('inprogress').style.visibility='visible'">

Note that there is an image used in the in-progress message, this is important. A static “Please Wait” message tells your user they should wait, but without the feedback of the moving image, they could still get the impression something is locked up. You can get some awesome free progress meters from http://www.ajaxload.info.

Of course Internet Explorer throws a wrench into things. IE will stop any animated gifs from animating when the form is submitted. This is a problem in IE6 and 7. This is far worse than having no progress meter, since it appears as if something has locked up. But there is a work around. We just need to kick start the animation after the form submits. We do this by resetting the source of the image with JavaScript. We have to reset the src after the form submits, and the form submits when our function returns. So we make use of the setTimeout function, which executes a line of JavaScript after a specified number of milliseconds. We’ll also throw in an anti-double submit feature similar to what I mentioned in my last post.

<script language="JavaScript">
var submitted = false;
function doSubmit() {
	if (! submitted) {
		submitted = true;
		ProgressImg = document.getElementById('inprogress_img');
		document.getElementById("inprogress").style.visibility = "visible";
		setTimeout("ProgressImg.src = ProgressImg.src",100);
		return true;
		}
	else {
		return false;
		}
	}
</script>

<input type="submit" onclick="return doSubmit()">

If your form is long enough that it needs scroll bars, be sure to place the in-progress message where the user will see it when they click the submit button.

10 Responses to “Animated in-progress indicator for long running pages”

  1. Ikesacolick Says:

    Good solution. Thank You.

    One small issue. To get this to work, you need to set the id=’inprogress_img’ in the img tag as in:

    img id=”inprogress_img” src=”progress.gif”

  2. Ryan Stille Says:

    Good call, I missed that in my example. Its been updated now.

  3. gesmith Says:

    Thanks for this very good solution. No thanks to IE and all of it’s headaches. :X

  4. Andrew Violette Says:

    Perfect. Worked like a charm!

  5. Stephen Scotti Says:

    I’m wanting to do something like this also, but instead of submitting a form I’m using a

  6. aearly Says:

    Nice solution! Glad you found a way around this problem.

  7. Andrisi Says:

    Nice, but how (where) do I hide the progress image?

  8. MJJ Says:

    Hi can i know how to hide the progress image when the processing is over? Thanks!

  9. Muthu Says:

    Thanks ! Can you let me know, if there is a way to keep the position of the image dyanmic? next to cursor/ mouse pointer ?

  10. Gary Says:

    With the ajaxload noted above this was the perfect solution for what I was trying to do.  Thanks much!

Leave a Reply