1

I am creating bidding website. I want when somebody place a bid for a particular product, the bid time should automatically increase by 1 minute.

e.g The current timer shows 20 sec . It means 20 sec left to place a bid. The i place my highest bid. Then i want as soon as i bid, the timer changes to 1 min 20 sec. It means 1 minute more left to place a bid. It means there is a opportunity for others also to place a bid.

user
  • 217
  • 1
  • 10
  • 2
    LOL `// watch for spelling` haha. excellent. p.s. you'll never knock off madbid!! and this is not enough code to go off.. please provide examples of how you have tried to implement it yourself and we can help where you went wrong.. were not here to do it for you, but to help with issues. – RaggaMuffin-420 Mar 11 '15 at 12:00
  • I don't know how to do that's y i put this question.If u don't want to answer then its ok. – user Mar 11 '15 at 12:17
  • 2
    You'll find very few people here who are willing to do the work for you is all i'm saying... you need to try and figure it out, then ask questions on specific areas you are struggling with... thats how this works. if you pay me I'll do it for you... PM for more information!! – RaggaMuffin-420 Mar 11 '15 at 12:28
  • Where is the time being stored? If multiple users are bidding on an item, there needs to be 1 authoritative timestamp which decides when a bid is done. Any user bidding should update that shared timestamp. When a page is refreshed, that timestamp is used to pre-populate how long there is remaining. In short, you need a database to store the "FinalBidTime" value. Then clicking the button updates the appropriate row in the table. One other thought... What if there's 10 minutes left and then 20 people bid within a minute? Now there's 29 mins left. You may only want to extend if < 10 mins left – Basic Mar 11 '15 at 12:48

1 Answers1

1

I saw a similar question at : The simplest possible JavaScript countdown timer?

I did an update, see it below

HTML

<body>
    <div>You have <span id="time">00:20</span> to bid!</div>
    <button>Bid !</button>
</body>

JS

var myCounter= (function() {
    var secondsleft= '';
    var timeleftinterval= null;

    var startTimer= function(duration) {
        var me= this;
        var timer = duration;
        var display = $('#time');

        me.timeleftinterval= setInterval(function () {
            minutes = parseInt(timer / 60, 10)
            seconds = parseInt(timer % 60, 10);           
            me.secondsleft= timer;

            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;

            display.text(minutes + ":" + seconds);

            if(--timer < 0) {
                clearInterval(me.timeleftinterval);
            }

        }, 1000);
    };

    var increaseTime= function(secondstoincrease) {
        clearInterval(this.timeleftinterval);
        this.secondsleft += secondstoincrease;
        this.startTimer(this.secondsleft);
    };

    return {
        startTimer: startTimer,
        increaseTime: increaseTime
    }
})();


jQuery(function ($) {
    myCounter.startTimer(20);
    $('button').click(function() {
        myCounter.increaseTime(60);
    });
});

http://jsfiddle.net/df773p9m/10/

Does it help you?

Community
  • 1
  • 1
angellica.araujo
  • 298
  • 1
  • 12