Forum Moderators: coopster

Message Too Old, No Replies

Using PHP to initalize variables in JS

         

wglenn01

9:52 pm on Nov 9, 2009 (gmt 0)

10+ Year Member



Ok all.

I need some help here i've been stuck with this for 2 hours now. It HAS to be so simple but mabey i'm overlooking something.

I have this code, and I made comments in the code to help I hope :)

$(document).ready(function() {

<?
// Do Time Stuff
// This turns my ending time into a useable format. I thought....
$date_f = date("m/d/Y h:i:s", $product->timeending);
?>

// Here we use the $date_f to set the ending time in a javascript countdown timer. The commented var d works great, the uncommented does not work.

var d = new Date("<? echo "$date_f"; ?>")
//var d = new Date("12/12/2009 12:00:00")

$('#defaultCountdown').countdown({until: d, expiryUrl: 'http://gotourl.com', format: 'MS'});

});

Any help would be SO appreciated!

eelixduppy

9:56 pm on Nov 9, 2009 (gmt 0)



Hello and Welcome to WebmasterWorld!

When you view the generate source code, what does that line produce?

wglenn01

9:58 pm on Nov 9, 2009 (gmt 0)

10+ Year Member



$(document).ready(function() {

var d = new Date("11/09/2009 03:57:24")
//var d = new Date("12/12/2009 12:00:00")
$('#defaultCountdown').countdown({until: d, expiryUrl: 'http://example.com', format: 'MS'});

});

That's it :)

[edited by: eelixduppy at 10:46 pm (utc) on Nov. 9, 2009]
[edit reason] exemplified [/edit]

wglenn01

10:38 pm on Nov 9, 2009 (gmt 0)

10+ Year Member



I figured it out. AM/PM makes a big difference. Thank you!