I’m using this jQuery countdown plugin: http://keith-wood.name/countdown.html
I’m trying this to set the countdown date:
var countdownValue = $('#countdown-value').text();
alert(countdownValue);
var newYear = new Date(countdownValue);
$('#countdown-l').countdown({until: newYear});
Div to set value:
<div id="countdown-value" style="display:none">2011, 07-1, 13</div>
The alert is returning ‘2011, 07-1, 13’.
That’s what I have entered in the db, so that’s correct. But the countdown is returning NaN for each number. However, if I directly enter 2011, 07-1, 13, I get a working countdown. Are there hidden characters, or is this parsed a different way?
I’m kinda lost here. Any thoughts?
The problem is that when you instantiate a
Dateobject like this:(By the way, the
07-1just resolves to 6, not sure if this is intended)You’re calling the
Dateconstructor with the following version:This is successful, because it creates a valid date. When you call the
Dateconstructor with$('#countdown-value').text(), you are initializing a newDatewith the version that takes a string, essentially:Which is not a valid date string.
To fix this, you can either make the date you are retrieving a valid date string, or parse out the values (Note that to make this method work easily, you’ll have to change 07-1 to “6”):
http://jsfiddle.net/vtFkd/