akshay Posted July 5, 2010 Share Posted July 5, 2010 Hi. I'm working on this JS Countdown timer (I'm a PHP Programmer, not a JS!) Anyone knows how to set TargetDate & FinishMessage variable? I've tried it as shown below, but it assumes PHP inserted value <?php...?> to be undefined as shows default values from countdown.js <html> <body bgcolor="#8cc63e" > <font face="Verdana" style="font-size: 24" color="white"> <?php session_start(); date_default_timezone_set("UTC"); if (!isset($_GET['f']) || !isset($_GET['s']) || !isset($_GET['dlpath']) || !isset($_GET['sessid'])) { echo "<b>INVALID <br> REQUEST</b>"; exit; } else { $realsessid=session_id(); $sessid=$_GET['sessid']; if ($sessid!=$realsessid) { echo "<b>INVALID <br> REQUEST</b>"; exit; } } $s=$_GET['s']; $f=$_GET['f']; $dlpath=urlencode($_GET['dlpath']); $dlpathtok=md5($dlpath); $link= '<a href="http://my-site.web/dl/launchdl.php?f='.$f.'&dlpath='.$dlpath.'&sessid='.$sessid.'&dlpathtok='.$dlpathtok.' " target="_blank"><img src="http://my-site.web/images/btn_download.png" alt="Download!" border=0></a>'; $time=time()+$s; $target=date("m/d/Y h:i A",$time); echo $target."<br><br>"; ?> <script language="JavaScript"> // TargetDate = "07/05/2010 9:00 AM" //By Default TargetDate = "<?php echo $target; ?>"; //mine entered BackColor = "#8cc63e"; ForeColor = "white"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = " %%S%% "; FinishMessage = "HELLO"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script> </font> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/ Share on other sites More sharing options...
sasa Posted July 5, 2010 Share Posted July 5, 2010 you are in right way to set that variables what is error Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081393 Share on other sites More sharing options...
akshay Posted July 5, 2010 Author Share Posted July 5, 2010 No error in PHP But js picks up default values as mentioned in "countdown.js" & not as mentioned in the code. I cant modify countdown.js as it cannot accept php variables!!! please help! Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081394 Share on other sites More sharing options...
sasa Posted July 5, 2010 Share Posted July 5, 2010 i try this part of code <html> <body bgcolor="#8cc63e" > <font face="Verdana" style="font-size: 24" color="white"> <?php $time=time()+20; $target=date("m/d/Y h:i:s A",$time); echo $target."<br><br>"; ?> <script language="JavaScript"> // TargetDate = "07/05/2010 9:00 AM" //By Default TargetDate = "<?php echo $target; ?>"; //mine entered BackColor = "#8cc63e"; ForeColor = "white"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = " %%S%% "; FinishMessage = "HELLO"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script> </font> </body></html> an it works for me Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081400 Share on other sites More sharing options...
akshay Posted July 5, 2010 Author Share Posted July 5, 2010 dude. You'd see seconds counting down for sure...but it would become a loop, u see... once they reach 0, they start again (it looks like a loop, but actually the code follows the date of 2020 as in JS...) and u see, there's no finish msg displayed! Or do u see one? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081403 Share on other sites More sharing options...
sasa Posted July 5, 2010 Share Posted July 5, 2010 yes i see [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081416 Share on other sites More sharing options...
akshay Posted July 5, 2010 Author Share Posted July 5, 2010 THANKS A LOT MAN!!!! Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081422 Share on other sites More sharing options...
akshay Posted July 5, 2010 Author Share Posted July 5, 2010 Yet not working =( Any simple code...?I dont know... Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081429 Share on other sites More sharing options...
jcbones Posted July 5, 2010 Share Posted July 5, 2010 OK, couple of things. The script is looking at your display format, Currently you have it set to seconds, so if you enter in more than 60 seconds, it will loop until the counter reaches 0. You can see this if you set the variable to: DisplayFormat = " %%M%% Minutes %%S%% Seconds"; You would also need to make sure that your variable $s is an integer. $s = (int)$_GET['s']; //or $s = int_val($_GET['s']); Quote Link to comment https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/#findComment-1081438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.