Page 1 of 1
javascript code, what´s bad here?
Posted: Thu Mar 29, 2007 6:36 pm
by visonardo
it would show "actualiza en xx segundos." where appear <div id="redirect2"></div> but dont work, what is bad here?
Code: Select all
<div id="redirect2"></div>
<script language="JavaScript">
// segundos para refresh
var countdownfrom=100;
var currentsecond=document.getElementById("redirect2").innerHTML="Actualiza en "+(currentsecond+1)+" segundos.";
//var currentsecond=document.getElementById("redirect2").innerHTML=currentsecond+1;
function countredirect(){
if (currentsecond!=1){
currentsecond-=1;
document.getElementById("redirect2").innerHTML="Actualiza en "+currentsecond+" segundos.";
//document.getElementById("redirect2").innerHTML=currentsecond;
}else{
document.location.reload();
return
}
setTimeout("countredirect()",1000);
}
countredirect();
</script>
Posted: Thu Mar 29, 2007 6:45 pm
by nickvd
"Don't work" can mean many different things. Are you getting any javascript warnings or errors?
Posted: Thu Mar 29, 2007 6:55 pm
by visonardo
nickvd wrote:"Don't work" can mean many different things. Are you getting any javascript warnings or errors?
no, just that dont show that i want, what is bad?
for example, it would show first "Aactualiza en 100 segundos."
then its change to 99, then to 98 and thus, when is 0 the page is reloaded
Posted: Thu Mar 29, 2007 7:10 pm
by nickvd
This line
Code: Select all
var currentsecond=document.getElementById("redirect2").innerHTML="Actualiza en "+(currentsecond+1)+" segundos.";
is a little strange. What is its intended purpose? Currently, it's setting current second to "Actualiza....". Later, you're trying to add one to it.
<edit>
Since I'm in a nice mood

The following
Code: Select all
var countdown = 7;
function countredirect(){
if (countdown >= 1){
document.getElementById("redirect2").innerHTML="Actualiza en " + countdown + " segundos.";
countdown -= 1;
} else {
document.location.reload();
}
setTimeout("countredirect()",1000);
}
countredirect();
works just fine...
Posted: Thu Mar 29, 2007 9:18 pm
by visonardo
nickvd wrote:This line
Code: Select all
var currentsecond=document.getElementById("redirect2").innerHTML="Actualiza en "+(currentsecond+1)+" segundos.";
is a little strange. What is its intended purpose? Currently, it's setting current second to "Actualiza....". Later, you're trying to add one to it.
<edit>
Since I'm in a nice mood

The following
Code: Select all
var countdown = 7;
function countredirect(){
if (countdown >= 1){
document.getElementById("redirect2").innerHTML="Actualiza en " + countdown + " segundos.";
countdown -= 1;
} else {
document.location.reload();
}
setTimeout("countredirect()",1000);
}
countredirect();
works just fine...
yes, youare right. i didnt remember that the value where i wont keep this string is used again. Thank you nickvd
Posted: Thu Mar 29, 2007 9:48 pm
by visonardo
Code: Select all
<div id="redirect2"></div>
<script language="JavaScript">
// segundos para refresh
var countdownfrom=60
var currentsecond=countdownfrom+1;
document.getElementById("redirect2").innerHTML="Actualiza en severals segundos.";</script>
the <div id=""></div> dont show that must :S
i did this easy to start to see what happen because dont work the mine
Posted: Thu Mar 29, 2007 10:58 pm
by feyd
Javascript = Client Side.
Posted: Fri Mar 30, 2007 9:25 pm
by visonardo
does someone know what is bad in my code?

Posted: Fri Mar 30, 2007 9:39 pm
by Kieran Huggins
you're missing a colon on line 1: "var countdownfrom=60;"
you should use setInterval() instead of setTimeout.
Posted: Fri Mar 30, 2007 11:34 pm
by visonardo
Thank to all, the problem was that i was testing that just in a txt for example, the tag <script ..> was not between heads tags.