Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2013, 04:50 PM   PM User | #1
Mcoffman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Mcoffman is an unknown quantity at this point
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?
Mcoffman is offline   Reply With Quote
Old 02-08-2013, 06:54 PM   PM User | #2
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
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
teedoff is offline   Reply With Quote
Old 02-08-2013, 06:58 PM   PM User | #3
Mcoffman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Mcoffman is an unknown quantity at this point
How could I accomplish that?
Mcoffman is offline   Reply With Quote
Old 02-08-2013, 07:11 PM   PM User | #4
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
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
teedoff is offline   Reply With Quote
Old 02-08-2013, 07:13 PM   PM User | #5
Mcoffman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Mcoffman is an unknown quantity at this point
Ive searched all over for a free one and couldn't find one.
Mcoffman is offline   Reply With Quote
Old 02-10-2013, 01:05 PM   PM User | #6
mzpresto
New Coder

 
Join Date: Aug 2012
Posts: 45
Thanks: 15
Thanked 0 Times in 0 Posts
mzpresto is an unknown quantity at this point
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
mzpresto is offline   Reply With Quote
Old 02-10-2013, 02:53 PM   PM User | #7
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 368
Thanks: 3
Thanked 44 Times in 44 Posts
Airblader can only hope to improve
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.
Airblader is offline   Reply With Quote
Old 02-11-2013, 04:14 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-11-2013, 08:21 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-18-2013, 01:31 PM   PM User | #10
Mcoffman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Mcoffman is an unknown quantity at this point
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.
Mcoffman is offline   Reply With Quote
Old 02-18-2013, 03:29 PM   PM User | #11
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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".
__________________

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.

Last edited by Philip M; 02-18-2013 at 06:35 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:46 AM.


Advertisement
Log in to turn off these ads.