Web Analytics Made Easy -
StatCounter Countdown in an auction - CodingForum


No announcement yet.

Countdown in an auction

  • Filter
  • Time
  • Show
Clear All
new posts

  • Countdown in an auction

    Hello all,

    Roy from the north of the world here

    I've been looking around to see if there is a answare for this question here, but could not find it.

    I'm planning on making a auction on a web page where the bid is held in an database. If there is a bid in the last x minuts before closing, the auction shold last for x more minuts/seconds.

    I then need a countdown, showing on the page, that changes the countdown time if there is a new bid. I don't understand how to get the "new" time when a "last minut bid" is entered.

    Anyone that could give me an idea how to do this?

    Any assistance would be apprecaited. Thank You for your time!


  • #2
    Well, thanks for the question; It's been a while since I've had a reason to write a script more than 10 lines long.

    <script type="text/javascript">
    var condition = minutesinput + hoursinput

    //The variables secondsinput, minutesinput, and hoursinput are the amount of seconds, minutes, and hours the person input for the auction.

    while(secondsinput > 0){
    if(secondsinput = 0 && condition > 0){
    var secondsinput = 60;
    if(minutesinput == 0 && hoursinput > 0){
    var minutesinput = 59
    }else if(minutesinput > 0){
    function delay(){}
    document.write("There are " + hoursinput + " hours left, " + minutesinput + " minutes left, and " + secondsinput + " seconds left in this auction")
    <body onLoad="setTimeout('delay()', 1000)">
    var currentTime = new Date()
    var chance = currentTime.getTime()
    var chance2 = chance % 3


    • #3
      I would just do some sort of request (XMLHTTP, an iframe or even just refresh the page, I don't know your set up) to the server just before the bidding is set to close to check to see if it has been extended. Then just give some sort of notification at that time saying the bidding has been extended. The end user has no idea when another person's bid was actually placed, so the timer inaccuracy for a few minutes is moot.

      Last edited by Basscyst; Sep 28, 2006, 01:21 PM.
      Helping to build a bigger box. - Adam Matthews


      • #4
        To clear up any misunderstandings, I attach the code here:

        <BODY style="margin: 0px; background: #c0c0c0;" onLoad="TellNed();">

        <table border="0" cellspacing="0" cellpadding="0"><tr valign="top">
        //Select-statement to get the right time from the database
        sekunder = res("tekst")

        var RestSekunder = <%=sekunder%>;
        var VedStart = 55;

        function TellNed()
        Kalk = RestSekunder

        dager = Math.floor(Kalk / 86400);
        Kalk -= dager * 86400;

        timer = Math.floor(Kalk / 3600);
        Kalk -= timer * 3600;

        minutter = Math.floor(Kalk / 60);
        Kalk -= minutter * 60;

        var Tekst = '';

        if(BudBoks.style.visibility == 'hidden') {Tekst = 'Auksjonen har ikke startet ennه!<br><br>';}

        if(RestSekunder > 0)
        Tekst = Tekst + 'AUKSJONEN SLUTTER OM: <br><font style="font-size: 24pt;"><b>';
        if(dager > 0) {Tekst = Tekst + dager + ' d ';}
        if(timer > 0) {Tekst = Tekst + timer + ' t ';}
        if(minutter >0) {Tekst = Tekst + minutter + ' m ';}
        Tekst = Tekst + Kalk + ' s</font></b>';
        if (VedStart <= 0) {
        NedtellingTabell.style.background = '#ffcccc';
        NedtellingTabell.style.border = '3px solid #FE0000';
        Tekst = 'AUKSJONEN ER AVSLUTTET<br><br><a href="visNesteAuksjon.aspx?id=94095" style="color: black;">Sjekk evt. neste auksjon her</a>';
        BudBoks.innerHTML = '';
        Nedtelling.innerHTML = Tekst
        if(RestSekunder>0) {setTimeout(TellNed,1000);}

        <td align="center"><b><span style="font-size: 11pt;" id="Nedtelling">LASTER INN AUKSJON...</span></b><span id="BudBoks"></span></td>

        This code gets the time when the auction should end from my database, but if another user give a bid i want the extend the time to bid with e.g. 60 seconds and update this in the countdown.

        Hope my code makes my question a bit more clear


        • #5
          I understand you have a timer monitoring the amount of time is left on an auction. When User A places a bid you want User B's timer to update and add x amount of time to the auction if the bid time is within x minutes of the auctions close time.

          To answer your question directly, you could set a timer to trigger an iframe refresh or an ajax call once every second or so once the auction is within x minutes of close.

          How are you notifying the User B of User A's bid in the first place? It seems like the time left on the auction could be incorporated into whatever you are doing to do that.

          If User B has no idea when a bid was actually placed by User A, upon expiration of the current timer, you probably get updated information from the server, you could just wait till the current timer expires. Then instead of closing the bidding to the user immediatly, first check to see if there were new bids and reset the timer accordingly notifying the user if there are.

          Both would work, the first idea is more real time, but is rather resource intensive.

          Last edited by Basscyst; Sep 28, 2006, 06:25 PM.
          Helping to build a bigger box. - Adam Matthews


          • #6
            I'm not familiar with iframe or ajax, but i will look into it!

            Thanks for the help.