Refresh Div content
-
I am making a school project based on jsp, i have a page in the solution which shows an animated Redirecting using following code
var ic = 0; var s0 = "Redirecting"; var s1 = "Redirecting."; var s2 = "Redirecting.."; var s3 = "Redirecting..."; function redir() { ic++; switch(ic) { case 1: $('#text').html(s0); break; case 2: $('#text').html(s1); break; case 3: $('#text').html(s2); break; case 4: $('#text').html(s3); ic = 0; break; default: $('#text').html(s0); ic = 0; } setTimeout(redir(), 500); return 0; }
Problem is the div does not refresh (shows only "Redirecting." without any change) periodically with the text change calls. Thanks in advance -
I am making a school project based on jsp, i have a page in the solution which shows an animated Redirecting using following code
var ic = 0; var s0 = "Redirecting"; var s1 = "Redirecting."; var s2 = "Redirecting.."; var s3 = "Redirecting..."; function redir() { ic++; switch(ic) { case 1: $('#text').html(s0); break; case 2: $('#text').html(s1); break; case 3: $('#text').html(s2); break; case 4: $('#text').html(s3); ic = 0; break; default: $('#text').html(s0); ic = 0; } setTimeout(redir(), 500); return 0; }
Problem is the div does not refresh (shows only "Redirecting." without any change) periodically with the text change calls. Thanks in advance<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var ic = 0;
var s0 = "Redirecting";
var s1 = "Redirecting.";
var s2 = "Redirecting..";
var s3 = "Redirecting...";
function redir(ic) {
ic++;
switch(ic) {
case 1:
$('#text1').html(s0);
break;
case 2:
$('#text1').html(s1);
break;
case 3:
$('#text1').html(s2);
break;
case 4:
$('#text1').html(s3);
ic = 0;
break;
default:
$('#text1').html(s0);
}
if(ic > 0){setTimeout("redir("+ic+")", 500);}
return 0;
}
</script>
</head>
<body>
<div id="text1"></div>
<script>
redir(ic);
</script>
</body>
</html>This works but you really should change the code to use use setInterval instead of setTimeout
modified on Saturday, July 31, 2010 2:01 PM
-
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var ic = 0;
var s0 = "Redirecting";
var s1 = "Redirecting.";
var s2 = "Redirecting..";
var s3 = "Redirecting...";
function redir(ic) {
ic++;
switch(ic) {
case 1:
$('#text1').html(s0);
break;
case 2:
$('#text1').html(s1);
break;
case 3:
$('#text1').html(s2);
break;
case 4:
$('#text1').html(s3);
ic = 0;
break;
default:
$('#text1').html(s0);
}
if(ic > 0){setTimeout("redir("+ic+")", 500);}
return 0;
}
</script>
</head>
<body>
<div id="text1"></div>
<script>
redir(ic);
</script>
</body>
</html>This works but you really should change the code to use use setInterval instead of setTimeout
modified on Saturday, July 31, 2010 2:01 PM
well thanks mate, cheers but i have edited your code a bit to just meet that edge:
function redir(ic) { ic++; switch(ic) { case 1: $('#text1').text(s0); break; case 2: $('#text1').text(s1); break; case 3: $('#text1').text(s2); break; case 4: $('#text1').text(s3); ic = 0; break; default: $('#text1').text(s0); } setInterval("redir("+ic+")", 500); return 0; } </script>
-
well thanks mate, cheers but i have edited your code a bit to just meet that edge:
function redir(ic) { ic++; switch(ic) { case 1: $('#text1').text(s0); break; case 2: $('#text1').text(s1); break; case 3: $('#text1').text(s2); break; case 4: $('#text1').text(s3); ic = 0; break; default: $('#text1').text(s0); } setInterval("redir("+ic+")", 500); return 0; } </script>
Shantanu Gupta 1337 wrote:
but i have edited your code a bit to just meet that edge:
You have edited your own code which I had modified. If it were my code it would look like this ...
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var redir = (function(){
this.ic = 0;
this.ar = arguments;
return function(){
if(++ic == ar.length){ic = 1;};
$('#'+ar[0]).html(ar[ic])};})
("text1","Redirecting","Redirecting.","Redirecting..","Redirecting...")
</script>
</head>
<body>
<div id="text1"></div>
</body>
<script>
setInterval(redir,500);
</script>
</html>modified on Sunday, August 1, 2010 4:40 PM