Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progressbar doesn't stickaround onSubmit- HELP! 1

Status
Not open for further replies.

heckler0077

Programmer
May 20, 2007
3
US
Hello. I haven't gotten around to learning js yet, so I found the script that I needed online. I actually combined it with another to make what I need, which is that when you click on a button or a link or something like that, if you have specified a certain href (for the link) or onSubmit (for a form) or onClick (for a specific button, ie submit in the form) it pops up a processing bar. I want to add this to certain pages so that when you click the submit button, the js progress bar shows for about 2 seconds, and then it goes to the page that the form's action attribute specified, carrying whatever form data it needs. I want to be able to use post or get as my method. All of this works fine, if, instead of a submit button, I use a regular button, because I'm not specifying an action, so the clicking of the button just launches the processing bar. When I have an action and a button that sends the form data, such as submit, I run into my problem: the processing bar pops up for a moment and freezes, because the next page is starting to load, so even though the old page is still there for a few seconds while the new page loads, the javascript processing bar is still there, but not moving. How do I get this to work correctly, which once again, is that the user presses the submit button, the processing bar shows for about two seconds, and then it's okay if it freezes after the two seconds while the new page loads. The page is located at and you can look at the source to find the locations of the js documents and where they are in the page. Thank you!
 
Here is an inline example of how you can do this. In this example, I run the function showProgressBar() when the submit is clicked, then I set a timer to submit the form again in 2 seconds.
Code:
<html>
<head>
	<script type="text/javascript">
	function showProgressBar(form) {
		form.style.backgroundColor='red';
	}
	</script>
</head>
<body>
	<form name="myForm" onsubmit="showProgressBar(this);window['hndl']=(typeof window['hndl']=='undefined'||window['hndl']==null)?setTimeout('document.forms[\''+this.name+'\'].submit();',2000):null;return(window['hndl']==null);">
		<input type="submit" value="Click to send">
	</form>
</body>
</html>
Hope you can unravel it!

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
I am having a hard time integrating that with the current code. It works fin on it's own, and thank you very much, but I'm having trouble trying to get it to work.
 
Here is the complete code without Jeff's additions:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

<head>

<script type="text/javascript">
<!--
// xp_progressbar
// Copyright 2004 Brian Gosselin of ScriptAsylum.com
//
// v1.0 - Initial release
// v1.1 - Added ability to pause the scrolling action (requires you to assign
// the bar to a unique arbitrary variable).
// - Added ability to specify an action to perform after a x amount of
// - bar scrolls. This requires two added arguments.
// v1.2 - Added ability to hide/show each bar (requires you to assign the bar
// to a unique arbitrary variable).

// var xyz = createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )

var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;

function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
if(ie||w3c){
var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div>';
document.write(t);
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
bA.blocks=blocks;
bA.N=N;
bA.w=w;
bA.h=h;
bA.speed=speed;
bA.ctr=0;
bA.count=count;
bA.action=action;
bA.togglePause=togglePause;
bA.showBar=function(){
this.bar.style.visibility="visible";
}
bA.hideBar=function(){
this.bar.style.visibility="hidden";
}
bA.tid=setInterval('startBar('+N+')',speed);
return bA;
}}

function startBar(bn){
var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
t.style.left=-(t.h*2+1)+'px';
t.ctr++;
if(t.ctr>=t.count){
eval(t.action);
t.ctr=0;
}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}
-->
</script>

<title></title>
</head>
<body>
<style type="text/css">
@import url("/css/progress_bar.css");
</style>

<script type="text/javascript">
<!--
//Progress Bar script- by Todd King (tking@igpp.ucla.edu)
//Modified by JavaScript Kit for NS6, ability to specify duration
//Visit JavaScript Kit ( for script

var duration=10 // Specify duration of progress bar in seconds
var _progressWidth = 50; // Display width of progress bar

var _progressBar = new String("");
var _progressEnd = 10;
var _progressAt = 0;


// Create and display the progress dialog.
// end: The number of steps to completion
function ProgressCreate(end) {
// Initialize state variables
_progressEnd = end;
_progressAt = 0;

// Move layer to center of window to show
if (document.all) { // Internet Explorer
progress.className = 'show';
progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2);
} else if (document.layers) { // Netscape
document.progress.visibility = true;
document.progress.left = (window.innerWidth/2) - 100;
document.progress.top = pageYOffset+(window.innerHeight/2) - 40;
} else if (document.getElementById) { // Netscape 6+
document.getElementById("progress").className = 'show';
document.getElementById("progress").style.left = (window.innerWidth/2)- 100;
document.getElementById("progress").style.top = pageYOffset+(window.innerHeight/2) - 40;
}

ProgressUpdate(); // Initialize bar
}

// Hide the progress layer
function ProgressDestroy() {
// Move off screen to hide
if (document.all) { // Internet Explorer
progress.className = 'hide';
} else if (document.layers) { // Netscape
document.progress.visibility = false;
} else if (document.getElementById) { // Netscape 6+
document.getElementById("progress").className = 'hide';
}
}

// Increment the progress dialog one step
function ProgressStepIt() {
_progressAt++;
if(_progressAt > _progressEnd) _progressAt = _progressAt % _progressEnd;
ProgressUpdate();
}

// Update the progress dialog with the current state
function ProgressUpdate() {
var n = (_progressWidth / _progressEnd) * _progressAt;
if (document.all) { // Internet Explorer
var bar = dialog.bar;
} else if (document.layers) { // Netscape
var bar = document.layers["progress"].document.forms["dialog"].bar;
n = n * 0.55; // characters are larger
} else if (document.getElementById){
var bar=document.dialog.bar
}
var temp = _progressBar.substring(0, n);
bar.value = temp;
}

// Demonstrate a use of the progress dialog.
function Demo() {
ProgressCreate(10);
window.setTimeout("Click()", 100);
}

function Click() {
if(_progressAt >= _progressEnd) {
ProgressDestroy();
return;
}
ProgressStepIt();
window.setTimeout("Click()", (duration-1)*1000/10);
}

function CallJS(jsStr) { //v2.0
return eval(jsStr)
}
-->
</script>
<script type="text/javascript">
<!--
// Create layer for progress dialog
document.write("<span id=\"progress\" class=\"hide\">");
document.write("<FORM name=dialog>");
document.write("<TABLE border=2 bgcolor=\"#FFFFCC\">");
document.write("<TR><TD ALIGN=\"center\">");
document.write("Processing<BR>");
var bar1= createBar(300,15,'white',1,'black','blue',85,7,3,"");
//document.write("<input type=text name=\"bar\" size=\"" + _progressWidth/2 + "\"");
//if(document.all||document.getElementById) // Microsoft, NS6
//document.write(" bar.style=\"color:navy;\">");
//else // Netscape
//document.write(">");
document.write("</TD></TR>");
document.write("</TABLE>");
document.write("</FORM>");
document.write("</span>");
ProgressDestroy(); // Hides
-->
</script>


<form name="form2" action="/" onSubmit="CallJS('Demo()')" method="post">
<center>
<input type="submit" name="submit" value="Submit" />
</center>
</form>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top