473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Need help with simple progress bar

Why is my progress bar displayed only after it's reached 100%?

<html>
<style type="text/css">
#bar{
width: 10px;
height: 14px;
color: white;
font-size: 12px;
overflow: hidden;
background-color: red;
padding-left: 5px;
}
</style>

<head>
<script>
function setPercent(num){
document.getElementById("bar").style.width = num+ "px";
document.getElementById("bar").innerHTML= num + "%";
}
</script>
</head>
<body>

<div id="bar"></div>

<script>
var i = 0
while ( i < 100)
{
setPercent(i)
i++
}
alert("DONE")
</script>

</body>

</html>

Jun 30 '06 #1
6 4409
On Fri, 30 Jun 2006 09:36:50 -0500, john wrote:
Why is my progress bar displayed only after it's reached 100%?


It's not, it just looks like that. Add this delay loop to the setPercent()
function:

for(j=0;j<75000;j++);

Rich
Jun 30 '06 #2
Richard Gration said the following on 6/30/2006 11:03 AM:
On Fri, 30 Jun 2006 09:36:50 -0500, john wrote:
Why is my progress bar displayed only after it's reached 100%?


It's not, it just looks like that. Add this delay loop to the setPercent()
function:

for(j=0;j<75000;j++);


Did you test that? It doesn't do what you think it does.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 30 '06 #3
jo**@battlecreekonline.com said the following on 6/30/2006 10:36 AM:
Why is my progress bar displayed only after it's reached 100%?


Because it happens in about 2 ms of time. It gets updated, you just
don't see it being updated.
<script type="text/javascript">
var counter = 0;
function setPercent(num){
counter++;
if (counter>10)
{
document.getElementById("bar").style.width = counter + "px";
}
document.getElementById("bar").innerHTML= counter + "%";
if (counter == 100)
{
window.clearInterval(myInterval)
}
}

var myInterval = window.setInterval('setPercent()',60);
</script>
<div id="bar"></div>

And no, adding a counting loop is not the way to delay JS script.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 30 '06 #4
On Fri, 30 Jun 2006 11:39:45 -0400, Randy Webb wrote:
Richard Gration said the following on 6/30/2006 11:03 AM:
On Fri, 30 Jun 2006 09:36:50 -0500, john wrote:
Why is my progress bar displayed only after it's reached 100%?


It's not, it just looks like that. Add this delay loop to the setPercent()
function:

for(j=0;j<75000;j++);


Did you test that? It doesn't do what you think it does.


I did test it. Did you? It does exactly what I think it does in Opera
7.54, which is slow down execution. It might do more ... what do you think
it does?

Jun 30 '06 #5
Richard Gration said the following on 6/30/2006 12:02 PM:
On Fri, 30 Jun 2006 11:39:45 -0400, Randy Webb wrote:
Richard Gration said the following on 6/30/2006 11:03 AM:
On Fri, 30 Jun 2006 09:36:50 -0500, john wrote:

Why is my progress bar displayed only after it's reached 100%?
It's not, it just looks like that. Add this delay loop to the setPercent()
function:

for(j=0;j<75000;j++); Did you test that? It doesn't do what you think it does.


I did test it. Did you?


I wouldn't be asking if I hadn't. Although I didn't have to test it to
know what it was going to do.
It does exactly what I think it does in Opera 7.54, which is slow
down execution.
The way it does it is the problem. It doesn't cause a pause, it causes
the UA to become unresponsive because the JS engine is executing code
during that pause. Using setInterval, or setTimeout, to cause a pause
doesn't cause the UA to freeze up.
It might do more
It does, see above.
... what do you think it does?


Test it in IE and the freeze up becomes more obvious.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 30 '06 #6
I'm perfectly well aware of setInterval and how it's superior due to the
fact that the delay loop causes unresponsiveness. All I wanted was a quick
easy way for the OP to see his progress bar ... err, progress. Hands up, I
missed a golden opportunity for didactic rambling, but there ya go, that's
me.

Jun 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andras Gilicz | last post by:
Hi VB fans Is there a simple way to create a progress bar with a running % in the middle? The standard progress bar of VB6 cannot do it. How can I make the % number progressively inverted, as...
0
by: Martin Platt | last post by:
Hi, I'm looking into various options for a fairly simple backup utility for our application. I have no problems being able to backup, find restorable backup files, and restore then. What I'd...
19
by: trint | last post by:
Ok, I start my thread job: Thread t = new Thread(new ThreadStart(invoicePrintingLongRunningCodeThread)); t.IsBackground = true; t.Start(); There are lots of calls to controls and many...
3
by: SpamProof | last post by:
I got an animated gif that is a barber pole spinning that I want to use as a progress bar. The problem is that is stops spinning (shows 1 frame) when my browser is processing a submited request...
16
by: Crirus | last post by:
Hi there! This is the problem: I have a server that accept connections. Each request span a thread that handle it. I need a way to store the client IP's. If the requests made from a single IP...
5
by: Daves | last post by:
Hi, I'm using a asp.net 2.0 website to send out emails to users, the amount of which can reach up to 1500 users. Obviously the code sending the emails has to let the client know the mails are...
5
by: tommylux | last post by:
Hi there So far I have designed a simple template file in PHP: <?php if(!$page) $page="home"; if(file_exists("/my root/public_html/progress/$page.html")) { include("/my...
0
by: Gurpreet Singh | last post by:
Hi I am a newbie in Python I am creating a simple Tkinter based application. I have written Tkinter GUI source code and the programme logic in the same .py file. I am searching for a way...
2
by: mikelis | last post by:
I have a main form that does a lengthy database query. Before I fire off the query, I need to pop up another form that contains a progress bar and a Close button. The progress bar updates for 30...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.