29Jun
Animated progress/loading bar upon form submit - Javascript
Posted by admin as Javascript/AJAX
This piece of code displays an animated in progress bar after clicking the form submit.This is a good idea when your form is requiring large time when submitting information like file uploads.This will give the users the idea that the form action does not stuck up and is currently in progress.It does not require ajax,just javascript and some css and you can produce this animation.
First, you can download some cool,customizable and free loading icons at http://www.ajaxload.info. Then for the code:
Initially we will set the text and the image visibility to hidden.
You can put this code maybe beside your submit button so after clicking it the user can easily see the animation.
<p style=”visibility:hidden;” id=”progress”/><img id=”progress_image” style=”padding-left:5px;padding-top:5px;” src=”images/ajax-loader.gif” alt=”"> Uploading in progress…<p>
This is the javascript function that triggers and displays the image and the text.
function loadSubmit() {
ProgressImage = document.getElementById(’progress_image’);
document.getElementById(”progress”).style.visibility = “visible”;
setTimeout(”ProgressImage.src = ProgressImage.src”,100);
return true;}
The setTimeout function is for IE 6 and 7 users.This is because IE will stop any animated gifs from animating when the form is submitted.So we will display the image first(the animated one) then return the function to true.When the function returns to true, that is the time the form will submit,thus the users will see the loading icon first before the form submits.
Then trigger the function upon clicking your submit button.
<input class=”contSubmit” onclick=”return loadSubmit()” src=”images/submitinfo_btn.jpg” type=”image” />
Basically,that’s it.Just change the path of the images to where your images resides.Feel free to email me if you have any questions/suggestions.Thanks!
- Tags: Animated loading bar, Animated loading bar javascript, Animated progress bar, Animated progress bar javascript, form submit animation, form submit animation javascript, form submit loading animation, form submit loading animation javascript, form submit progress bar animation, form submit progress bar animation javascript













17 Responses to Animated progress/loading bar upon form submit - Javascript
tobyb
July 8th, 2009 at 4:47 pm
Thanks for this, the basic idea works, but you need to change a few things in your javascript to make this work:
function loadSubmit() {
var ProgressImage = document.getElementById(’progress_image’);
document.getElementById(”progress”).style.visibility = “visible”;
setTimeout(function(){ProgressImage.src = ProgressImage.src},100);
return true;
}
very minor changes, but they should fix any errors
admin
July 9th, 2009 at 7:33 am
my function works in me,maybe some addition will enhance it just like you did.Thanks for the suggestion toby!
tomm
August 24th, 2009 at 4:51 am
Hi, After making some changes this works fine in Chrome / Firefox but no luck in ie even upping the time-out. Any suggestions?
Thanks. T
darren
September 8th, 2009 at 5:03 pm
Just a quick note:
Your paragraph is an invalid element, you have closed it with />…
You need to remove the “/” so that it is closed properly with the element.
admin
September 8th, 2009 at 10:05 pm
edited out.Thanks Darren! I didn’t see that
Momo
September 24th, 2009 at 11:46 pm
Thanks for making the above code available. I am trying to install the animated progress bar but am having difficulty.
1. The image loads at startup. It does not wait for button submit.
2. I want to use button submit instead of form submit. Can you pls help.
3. What I am working on is - I would like to launch an exe (install) file from inside an hta window. This is working fine, the only problem is the loading gif image loads up when the page is launched. I want image to only launch after
4. Where do I put the javascript code? In the head or after the submit form/button?
Thanks.
admin
September 25th, 2009 at 12:46 am
Answers to your questions:
1.the image must be in a tag(in my example a <p> tag) that is set to be hidden on page load.
2.it can be on a submit button like this one:
<input type=”button” onclick=”return loadSubmit()”/>
3.you can put the javascript code anywhere you like,just enclose it in a
<script type=”text/javascript”> </script> tag.
Just place it in the head so you can easily locate it.
I hope I answer your questions correctly.Thanks!
Momo
September 25th, 2009 at 3:49 am
Thank you for your quick reply. I will try that!
Momo
September 25th, 2009 at 4:46 am
I want to use a css class image for the button because it matches the other buttons on the page. Can you please advise what code? My button is called
admin
September 25th, 2009 at 11:59 am
I have replied to your concern via email.Please check it out.
David
November 10th, 2009 at 8:59 pm
Great little script - very helpful - thank you very much!
Bryan Willman
December 4th, 2009 at 4:06 am
Thanks, something about that ‘return true;’ fixed a problem I was having where the gif would not animate.
Dong
January 7th, 2010 at 9:02 pm
I’m having a problem with the SUBMIT BUTTON.
This is the submit button code I modified:
input class=”contSubmit” shows a text field, not a button.
Please help
Dong
January 7th, 2010 at 9:08 pm
I fixed it… the problem was with the ‘ and “, which are italics when I copied in my editor. thanks.
Warren
January 7th, 2010 at 11:01 pm
I am loading data from 5 text files into a mysql database and I am trying to setup a loading bar to indicate the progress as they are loaded.
Found your script and was wondering how to use this or another script to show the loader.
Thanks
Warren
admin
January 8th, 2010 at 12:10 pm
if you want to show the progress of the percent of the data beinXg loaded or processed,maybe you can use some AJAX for it.
vinoth
February 10th, 2010 at 10:50 am
Hi ,bro its realy workin well i.E thanks alot.