JavaScript and client side scripting.
Moderator: General Moderators
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Thu Mar 29, 2007 6:36 pm
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>
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Thu Mar 29, 2007 6:45 pm
"Don't work" can mean many different things. Are you getting any javascript warnings or errors?
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Thu Mar 29, 2007 6:55 pm
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
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Thu Mar 29, 2007 7:10 pm
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...
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Thu Mar 29, 2007 9:18 pm
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
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Thu Mar 29, 2007 9:48 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Mar 29, 2007 10:58 pm
Javascript = Client Side.
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Fri Mar 30, 2007 9:25 pm
does someone know what is bad in my code?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Fri Mar 30, 2007 9:39 pm
you're missing a colon on line 1: "var countdownfrom=60; "
you should use setInterval() instead of setTimeout.
visonardo
Forum Contributor
Posts: 136 Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.
Post
by visonardo » Fri Mar 30, 2007 11:34 pm
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.