chandler Posted March 1, 2011 Share Posted March 1, 2011 Hi, here the bit of code: echo 'You\'ll be redirected in'; include('script.html'); echo 'secs. If not, click <a href="visit.php">here</a></div>.'; this is being displayed on 3 lines I want to have it all on 1 line, how is this done? (script.html is a javascript countdown clock) thanks Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/ Share on other sites More sharing options...
.josh Posted March 1, 2011 Share Posted March 1, 2011 remove whitespace, blanklines and <br/> type tags at the beginning and end of script.html Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181516 Share on other sites More sharing options...
jasonrichardsmith Posted March 1, 2011 Share Posted March 1, 2011 I would suggest not using a separate webpage for the countdown, I am not sure why you would do that, when you can use the same javascript on the same page. I would recommend you just use this jquery plugin and make it much easier. http://plugins.jquery.com/project/jquery-countdown echo 'You\'ll be redirected in <span id="countdown"></span> secs. If not, click <a href="visit.php">here</a></div>.'; Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181521 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 Hi, ok that looks good $('span.countdown').countdown({seconds: 30}); how would I add this to the code, I have tried keep getting errors. echo 'You\'ll be redirected in $('span.countdown').countdown({seconds: 30}); secs. If not, click <a href="visit.php">here</a>.'; ?? thanks Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181523 Share on other sites More sharing options...
jasonrichardsmith Posted March 1, 2011 Share Posted March 1, 2011 paste this in a file named jquery.countdown.js /** * jQuery's Countdown Plugin * * display a countdown effect at given seconds, check out the following website for further information: * http://heartstringz.net/blog/posts/show/jquery-countdown-plugin * * @author Felix Ding * @version 0.1 * @copyright Copyright(c) 2008. Felix Ding * @license http://www.opensource.org/licenses/bsd-license.php The BSD License * @date 2008-03-09 * @lastmodified 2008-03-09 17:48 * @todo error & exceptions handling */ jQuery.fn.countdown = function(options) { /** * app init */ if(!options) options = '()'; if(jQuery(this).length == 0) return false; var obj = this; /** * break out and execute callback (if any) */ if(options.seconds < 0 || options.seconds == 'undefined') { if(options.callback) eval(options.callback); return null; } /** * recursive countdown */ window.setTimeout( function() { jQuery(obj).html(String(options.seconds)); --options.seconds; jQuery(obj).countdown(options); } , 1000 ); /** * return null */ return this; } Put this at the top of your page <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" src="put.the.path.to.jquery.file.you.just.created"></script> Put this on the bottom of you page. I put all javascript on the bottom of the page per the Jquery cookbooks suggestion. <script type="text/javascript"> $(document).ready(function() { $('span.countdown').countdown({seconds: 30,window.location.replace("visit.php")}); }); </script> replace 30 with however long you want. keep this echo 'You\'ll be redirected in <span id="countdown"></span> secs. If not, click <a href="visit.php">here</a></div>.'; this should do everything for you Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181530 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 I get no errors, but there is no countdown displayed all I see is : Thank you, we will be in touch. You'll be redirected in secs. If not, click here. I have triple checked and all paths etc are correct. Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181541 Share on other sites More sharing options...
jasonrichardsmith Posted March 1, 2011 Share Posted March 1, 2011 Sorry should have checked it first. His callback "option" breaks its ability to work. replace this: <script type="text/javascript"> $(document).ready(function() { $('span.countdown').countdown({seconds: 30,window.location.replace("visit.php")}); }); </script> with the following: <script type="text/javascript"> $(document).ready(function() { $('#countdown').countdown({seconds: 5}) setTimeout(function() { window.location.href = "visit.php"; }, 5000); }); </script> no his seconds are 5 which equals the 5000 milliseconds in the setTimeout. I just tested this and it works. Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181564 Share on other sites More sharing options...
chandler Posted March 1, 2011 Author Share Posted March 1, 2011 that is so cool, many many thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/#findComment-1181573 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.