Forum Moderators: open
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function()
{
//Paleidimo funkcija
var time_ref = setTimeout(function()
{
var time_ref2 = setInterval(function()
{
$('#time_now').load('time.php?id='+ Math.random());
}, 1000);
}, 3000);
//Laiko sustabdymo funkcija
$("#stop").click(function()
{
clearInterval(time_ref2);
});
});
</script>
</head>
<body>
<div align="center" id="time_now">--:--:--</div>
<button id="stop">Stop</button>
</body>
</html>
I believe this is a variable scope problem. Basically, by putting "var " in front of the time_ref and time_ref2 variables inside that function, you are declaring those as local variables. Instead, remove the var from each. So those 3 lines would look like:
time_ref = setTimeout(function()
{
time_ref2 = setInterval(function()