Jump to content

echo out on one line?


chandler

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229304-echo-out-on-one-line/
Share on other sites

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>.';

 

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.