Jump to content

Kind of stuck


killah

Recommended Posts

Well, i currently have a javascript code. It count's down from 10 minute's to 0.

 

I can syncronize the count down to the database. But exactly how do i update the database per second using the javascript code?

 

<?php
$x_m = '10
';
$x_s = '59
';
?>

<script language="javascript">
var x_m = <?php echo $x_m; ?>
function startClockMinutes()
{
	if(x_m !== 0)
	{
		x_m = x_m - 1
		document.frm.clock_minutes.value = x_m + ' minute(s)'
		setTimeout("startClockMinutes()", 58999)
	}
	if(x_m == 0)
	{
		x_m = 9
		document.frm.clock_minutes.value = x_m + ' minute(s)'
	}
}
var x_s = <?php echo $x_s; ?>
function startClockSeconds()
{
	if(x_s !== 0)
	{
		x_s = x_s - 1
		document.frm.clock_seconds.value = x_s + ' seconds left'
		setTimeout("startClockSeconds()",1000)
	}
	if(x_s == 0)
	{
		x_s = 59
		document.frm.clock_seconds.value = x_s + ' seconds left'
	}
}
var times = 0
function set_times()
{
	times = times + 1
	document.frm.times.value = times + ' times'
	setTimeout("set_times()",1000)
}
</script>

<body onload="startClockSeconds(); startClockMinutes(); set_times();">

<form name="frm">
<input type="text" name="clock_minutes" readonly size="9" />
<input type="text" readonly style="text-align: center;" value="&" size="1" />
<input type="text" name="clock_seconds" readonly size="12" /><br />
<input type="text" name="times" readonly size="4" /><br />
</form>

 

You might see some wierd thing's. But it's for testing right now only. So can anyone tell me how i can update the database per second? If i can find that out, i can do the per minute one.

Link to comment
Share on other sites

[..]Just a questions, is there a reason you are using javascript for this instead of using a cron job?

 

Yes, i would like to let the user know when the next update is.

 

Can you provide the ajax script which will update every second?

Link to comment
Share on other sites

[..]Just a questions, is there a reason you are using javascript for this instead of using a cron job?

 

Yes, i would like to let the user know when the next update is.

 

Can you provide the ajax script which will update every second?

I could but instead lemme give you a link instead

http://lmgtfy.com/?q=periodical+ajax+call

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.