THE SCRIPT bELOW PASSED THE SECOND TO 0 (STARTING FROM 1500 SECOND) I NEED 1500 SECONDS THAT SHOW AS 00:25:59, 00:25:58................00:25:01...00:24:00...00:24:59........................UNTILL 00:00:00.

PLZ HELP ME

<HTML>
<BODY>
<script language="javascript" type="text/javascript">
var myTime = "1500";
function countDown() {
    document.form.seconds.value = "00:25:" + (myTime < 10 ? "0" + myTime : myTime);
    if (myTime == 0)
    {
        location.href="trivia1.php";
    }
    else if (myTime > 0)
    {
        myTime--;
        setTimeout("countDown()",1000);
    }
}
</script>

<body onload="countDown();">
<form name="form">
Time Left: <input type="text" name="seconds" size="10">
</form>
</body>
</HTML>

Please explain what the problem is? I ran your code and it counts down to zero and then tries to load your page. Is that what you want? Wait a minute, I get it.

Change your strings to integers, because you are forcing them to be that anyway. Change the "00:25" to an integer. I assume you want this integer to be reflected in the value of the variable myTime. Take whatever value that is there and do some simple math to pre-calculate what the display should be.

Run your loop with some changes. One way would be to add a test for minutes or seconds to know when you cross the 0 number. (myTime/60 = minutes minutes/60 = seconds.) When the transition point hits you can subtract from the value you need. A couple of if elseif and you should be finished. I can be of more help lter if you need. I'll look back.

Dear i need in simple word that i have a html page that should show the time as minutes not as seconds as in my scripts above

1)Your variable 'myTime' should be declare without quotations. It is better to do it as integer rather than a string.

2)Your attempt to display time is odd. You must not hard-coded the prefix of the display or you would get it wrong no matter what. What you really need to do is to compute minutes & seconds left from your myTime.

3)I would rather put the script inside 'head' tag.

4)You have 2 body tags and they are not closed properly!!!

Sample code is below...

<HTML>
<HEAD>
<script language="javascript" type="text/javascript">
var myTime = 1500;
function countDown() {
  var minute = Math.floor(myTime/60)
  var seconds = myTime-(minute*60)
  var out = (minute)>9 ? (""+(minute)) : ("0"+(minute))
  out += ":"
  out += (seconds)>9 ? (""+(seconds)) : ("0"+(seconds))
  document.form.seconds.value = out;
  if (myTime == 0) {
    location.href="trivia1.php";
  }
  else if (myTime > 0) {
    myTime -= 1;
    setTimeout("countDown()", 1000);
  }
}
</script>
</HEAD>

<BODY onload="countDown();">
<form name="form">
  Time Left: <input type="text" name="seconds" size="10" readonly>
</form>
</body>
</HTML>

Is this correct. When i pasted the above script to the notpad and save as html it does not work plz help

How did you save on the notepad? I believe that you save it as default which results the file as name.html.txt. When you save on notepad, you must type the name in with quotations (as "name.html" and not just name.html) and select the save file type as "All file."

Notepad puts a .txt on everything. Open your explorer and change the extension.

Notepad puts a .txt on everything. Open your explorer and change the extension.

The problem is that many people are not computer literate. The way you explain may not be working for them because Windows, by default, seems to set the explorer view to hide extension. As a result, they may not understand what you are saying. :)

I'm working on that. Sometimes the complaint is the other way, TMI. It's tough to hit a balance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.