Need help with javascript counter

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Columbo
Forum Newbie
Posts: 5
Joined: Sun Aug 09, 2009 1:55 pm

Need help with javascript counter

Post by Columbo »

Let me state right off the top that I know nothing about javascript.

I am trying to display a single string that says "Record has been added sucessfully" in a table and then have it display for about 5 seconds. After the 5 seconds is up, it will then redirect to another page.

Since I am working with a test file, it does not actually redirect, but simply displays the word "Done!" instead.

The problem I am having is that it seems to be running the timer first and then when the time is up, it displays the word "Done" and then displays the table with the string "Record has been added sucessfully" below it. Everything seems to be going in reverse order.
The code that I am using is:

Code: Select all

 
<html>
<head>
<title>Timed Display</title>
</head>
<body>
<center>
<table width="300px" height="100" style="border: 1px solid #000000;">
<tr><td align="center">
<script langage="javascript">
<!--
   document.write("Record has been added sucessfully");
 -->
</script>
</td></tr>
</center>
<script language="javascript">
<!--
   var timer=0;             
 for (count=1; count<=5000; count++){
    timer=count;  /* I don't need this but examples I looked at had something in here. */ 
    }
    document.write("Done!");
-->
</script>
<body>
<html>
 
Can anyone explain to me why it is working this way and how to achieve the intended goal?

Thanks
izzy4505
Forum Newbie
Posts: 16
Joined: Tue Aug 11, 2009 1:38 pm

Re: Need help with javascript counter

Post by izzy4505 »

It's working fine, but you forgot to close your table with </table>. Furthermore, never use a <center> tag.

Also, if you want a delay, simply counting to 5,000 isn't going to help you. Computers these days can do this very quickly.

Read up on it here:
http://www.tizag.com/javascriptT/javascriptredirect.php
Post Reply