0

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>

Edited by Nick Evan: Fixed formatting

3
Contributors
9
Replies
11
Views
6 Years
Discussion Span
Last Post by tinymark
0

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.

Edited by tinymark: n/a

0

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.

0

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

0

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>

Edited by Taywin: n/a

0

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

0

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."

Edited by Taywin: n/a

0

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. :)

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.