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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.