Forum Moderators: open
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function()
{
//Paleidimo funkcija
var time.ready(function()
{
$('#time_show').load('time.php?nu='+ Math.random());
});
});
</script>
</head>
<body>
<?php
if($name == "Marrko") {run jquery time functions}
?>
<div id="time_show"></div>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>$(document).ready(function(){
<?php
$city = "Paris";
if($city == "Paris"){ ?>
var time_ref2 = setInterval(function()
{
$('#time_now').load('time.php?id='+ Math.random());
}, 1000);
<?php } ?>
});
</script>
</head> <body> <div align="center" id="time_now">--:--:--</div>
</body> </html>
time.php:
<script type="text/javascript" src="jquery.js"></script>
<?php
$sec = date("s");
echo $sec;
?>
<script>$(document).ready(function(){
<?php
if($sec == "30"){ ?>
var stop = setInterval(function()
{
clearInterval(time_ref2);
}, 2000);
<?php } ?>
});
</script>
1. once per second, load the contents of time.php and display them in the #time_now div
2. in time.php, get the current time in seconds and print it out. If seconds = 30, stop the interval on the parent page.
the problems I see are:
1. time.php doesn't know what time_ref2 is. time_ref2 was created on the parent page, so it doesn't exist on time.php
2. since time.php doesn't know what time_ref2 is, it can't stop the associated interval.
3. I'm not sure why you are setting an interval on the stop line anyway -- why not just clearInterval(time_ref2) without surrounding it in a setInterval?
instead I would have some sort of a loop on the parent page that checks the contents of #time_now
something like:
if ( $('#time_now').html() == "30" ) {
// stop the interval
}
There are probably better ways to do it but off the top of my head that's what I'm thinking of first..