Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Countdown for price?

    Hello! I am trying to put a countdown for price online which would decrease the price of something by $.05 every minute. Is this possible?

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by Mcoffman View Post
    Hello! I am trying to put a countdown for price online which would decrease the price of something by $.05 every minute. Is this possible?
    Yes.

    How to accomplish that is another story, but it is possible.
    Teed

  • #3
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How could I accomplish that?

  • #4
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by Mcoffman View Post
    How could I accomplish that?
    There are literally thousands of sites out there that have free code for all kinds of counters. I'm almost positive you could even do a search on this site and get many examples.

    If you want to write your own custom code, it may be too much of an undertaking for an inexperienced coder at this point. But when there are many free sources, no need to do that.
    Teed

  • #5
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ive searched all over for a free one and couldn't find one.

  • #6
    New Coder
    Join Date
    Aug 2012
    Posts
    45
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mcoffman View Post
    Ive searched all over for a free one and couldn't find one.
    First try this:

    Try This

    If that doesn't work there are 25 Here:

    Try these

    and here is one that countdowns in dollars, but shouldn't be too hard to change

    This looks exactly like what you want

  • #7
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    And once again:

    If this actually concers an actual application and not just some toy example to learn, do not rely on JavaScript only. Anyone can manipulate it and put in any price they want.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    This is not suitable for Javascript, as in any case the time is the time as per the user's browser.

    You will need to use server-side code for this so that all users see the same price. Otherwise if I advance my computer clock by one hour I get the reduced price which will become applicable an hour in the future!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,597
    Thanks
    80
    Thanked 4,633 Times in 4,595 Posts
    Quote Originally Posted by Philip M View Post
    This is not suitable for Javascript, as in any case the time is the time as per the user's browser.

    You will need to use server-side code for this so that all users see the same price. Otherwise if I advance my computer clock by one hour I get the reduced price which will become applicable an hour in the future!
    Or if your website is in the USA, Philip doesn't have to do anything...as he is in the UK and several hours ahead. Or if your website is in the UK, then the same applies to, say, people in India.

    etc.

    It's nutso to depend on JavaScript for something like this!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is for a car dealer website. We have a Dutch auction running and u want to display this online with the price decreasing $3 per hour until it sells. I was going to put a disclaimer that said the price shown on the computer when they visit the showroom is the final price they could purchase the car for so the price would be verified in person before purchase. I still don't see an example on the above searches for a price countdown.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Code:
    <html>
    <head>
    
    <style type = "text/css">
    .showred {color:red; font-size:200%; font-weight:bold;}
    </style>
    </head>
    
    <body>
    
    <span id = "theprice" class = "showred" ></span>
    
    <script type = "text/javascript">
    
    function reducePrice() {
    
    var sd = new Date ("February 18th 2013 9:00");  // the starting date/time
    var sdt = sd.getTime();
    var p = 5000;  // the starting price;
    var now = new Date().getTime();
    var diff = now - sdt;
    var diffhrs = Math.floor(diff/1000/60/60);  // complete hours after start date/time
    var newprice = p - (diffhrs * 3);
    if (p < 0) {p=0}  // not to be negative!  You can set a minimum below which the price cannot fall.
    document.getElementById("theprice").innerHTML = "This wonderful car is now on sale at $" + newprice;
    
    }
    
    reducePrice();
    setInterval(reducePrice, 60000);  // update every minute
    
    </script>
    
    </body>
    </html>
    If you want the price to go down at the rate of $0.05 per minute rather than $3.00 per hour:-


    Code:
    <html>
    <head>
    
    <style type = "text/css">
    .showred {color:red; font-size:200%; font-weight:bold;}
    </style>
    </head>
    
    <body>
    
    <span id = "theprice" class = "showred" ></span>
    
    <script type = "text/javascript">
    
    function reducePrice() {
    
    var sd = new Date ("February 18th 2013 9:00");  // the starting date/time
    var sdt = sd.getTime();
    var p = 5000;  // the starting price;
    var now = new Date().getTime();
    var diff = now - sdt;
    var diffmins = Math.floor(diff/1000/60);  // minutes after start date/time
    var newprice = (p - (diffmins * .05)).toFixed(2);
    if (p <0 ) {p=0}  // not to be negative!
    document.getElementById("theprice").innerHTML = "This wonderful car is now on sale at $" + newprice;
    
    }
    
    reducePrice();
    setInterval(reducePrice, 30000);  // update every 30 seconds
    
    </script>
    But I would look at your legal position. You must make it clear that price shown on the site is only an invitation to treat and the prospective purchaser must attend the showroom.


    We are sorry that as a result of a typographical error we referred to General X as "a bottle-scarred old veteran". This should of course have read "a battle-scared old veteran".
    Last edited by Philip M; 02-18-2013 at 07:35 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •