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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Desperate help needed with script

Status
Not open for further replies.

edanlee

Technical User
May 21, 2005
4
US
i'm so lost, i need a countdown that starts at 5 mins counting down to 0 in the 0:00 format like "5:00,4:59,0:20"...you get the point. and a button that if you hit the button in the last minute it resets the timer to 1:30 (while still counting down)its part of a auction flash block. you can find a similar application at i tried this and had no luck. gotta admit i havent fully learned javascript. i need this badly though. please also if you code this for me leave your email so i can maybe donate or something. thank you so much,
Country
 
Country,

What have you tried so far?

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
admin320,

This shows you the necessary elements.
[tt]
<html>
<head>
<script language="javascript">
var hndtimer;
var dtrun;
var tsampling=1000; //millisecond
function tigging() {
//alert(dtrun);
var hh=Math.floor(dtrun/(60*60*1000));
var mm=Math.floor((dtrun-hh*60*60*1000)/(60*1000));
var ss=Math.floor((dtrun-hh*60*60*1000-mm*60*1000)/1000);

hh=((hh).toString().length<2)?"0"+hh:hh;
mm=((mm).toString().length<2)?"0"+mm:mm;
ss=((ss).toString().length<2)?"0"+ss:ss;

document.getElementById("timeleft").innerHTML=hh+":"+mm+":"+ss;
dtrun-=tsampling;
if (dtrun<0) stopit();
}

function doit() {
dtrun=90*60*1000; //01:30:00
tigging();
hndtimer=window.setInterval("tigging()",tsampling);
}
function stopit() {
window.clearInterval(hndtimer);
dtrun=0;
document.getElementById("timeleft").innerHTML="00:00:00";
alert("Time's up");
}
</script>
</head>
<body>
<div>Time left : <span id="timeleft"></span></div>
<button name="resettimer" onclick="doit()">start countdown (01:30)</button><br />
<button name="stoptimer" onclick="stopit()">&nbsp;stop countdown timer&nbsp;&nbsp;</button>
</body>
</html>
[/tt]
The rest is making thing look better and more versatile with more sophisticated validation routine---that is why thing looks much more complicated if you search for a ready-make countdown script on the net, which you won't fail to find plenty.

regards - tsuji
 
thats similar to what i'm talking about but it already is starting at 3:00 and clicking the button if time< 1:00 then the button would start timer at 1:30. but with everything i try when i click the button it restarts at 1:30 like i want it to but the seconds count down twice as fast.
 
dan,
its a auction script. for live biding... see its a 3-minute or 5-minute sale. if someone bids in the last minute then the timeleft on the sale would restart to 1:30 so that if two people want this item they both could compete on it.and time would not end if there is bidding in the last minute of the auction.

now when i tried writing a script for this it would restart at the time i needed but it wouldnt count down and if it did count down the seconds would count down in intergals of 2. i need it to be smooth and count down after reseting at 1:30 by the second
 

If it started counting down twice as fast after restarting it, it sounds like you weren't cancelling your original timer, and so both timers are firing.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

this script sets the original time at 5 minutes, and starts counting down once page is loaded. if a bid is made and the timer is under 1:30, the timer will reset to start counting again (with alert)...if the counter runs out, there is an alert that announces the end.

Code:
<script>
timeSX=60;
timeMX=5;
setTimer=0;
function bidNow() {
 if ((timeSX<30)&&(timeMX<2)) {
 timeSX=31;
 timeMX=1;
 alert("The auction has been extended for another minute and a half.");
 }
}
function counterX() {setTimeout("countDownX()",1000);}
function countDownX() {
timeSX=timeSX-1;
 if (setTimer==0) {
 timeMX=timeMX-1;
 document.getElementById('minutesX').innerHTML=timeMX;
 }
 if (timeSX<10) {timeSX='0'+timeSX;}
document.getElementById('minutesX').innerHTML=timeMX;
document.getElementById('secondsX').innerHTML=timeSX;
 if ((timeSX==0)&&(setTimer==1)) {
 timeSX=60;
 timeMX=timeMX-1;
 }
setTimer=1;
 if (timeMX<0) {alert("Auction is over!!");}
 else {counterX();}
}
</script>
<span style="font-weight:600;" id=minutesX name=minutesX>5</span><b>:</b><span style="font-weight:600;" id=secondsX name=secondsX>00</span> left in auction!<br>
<input type=button value="bid now" onclick=bidNow();>
<script>counterX();</script>

the problem is that a javascript-based timer reloads with the page, so it can be reset. do you base you timer on your server system time? the code gives you what you want, but i don't know if it's what you need...

- g
 

part II

you have to swap this function out for the previous one, there was a bug...

Code:
function bidNow() {
 if (timeMX<2) {
  if ((timeMX==0)||(timeSX<30)) {
  timeSX=31;
  timeMX=1;
  alert("The auction has been extended for another minute and a half.");
  }
 }
}

- g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top