0
Why is my Javascript code not working? My other codes always work, but this one doesn’t have to make it work. I want to put a date clock at the top of the page and I don’t want to leave those lines of code inside the index.
<SCRIPT LANGUAGE="javascript">
var now = new Date();
var mName = now.getMonth() +1 ;
var dName = now.getDay() +1;
var dayNr = now.getDate();
var yearNr=now.getYear();
if(dName==1) {Day = "Domingo";}
if(dName==2) {Day = "Segunda-feira";}
if(dName==3) {Day = "Terça-feira";}
if(dName==4) {Day = "Quarta-feira";}
if(dName==5) {Day = "Quinta-feira";}
if(dName==6) {Day = "Sexta-feira";}
if(dName==7) {Day = "Sábado";}
if(mName==1){Month = "Janeiro";}
if(mName==2){Month = "Fevereiro";}
if(mName==3){Month = "Março";}
if(mName==4){Month = "Abril";}
if(mName==5){Month = "Maio";}
if(mName==6){Month = "Junho";}
if(mName==7){Month = "Julho";}
if(mName==8){Month = "Agosto";}
if(mName==9){Month = "Setembro";}
if(mName==10){Month = "Outubro";}
if(mName==11){Month = "Novembro";}
if(mName==12){Month = "Dezembro";}
if(yearNr < 2000) {Year = 1900 + yearNr;}
else {Year = yearNr;}
var todaysDate =(" " + Day + ", " + dayNr + "/" + Month + "/" + Year);
document.write(' '+todaysDate);
</SCRIPT>
<SPAN ID="Clock">00:00:00</SPAN>
<SCRIPT LANGUAGE="JavaScript">
<!--
var Elem = document.getElementById("Clock");
function Horario(){
var Hoje = new Date();
var Horas = Hoje.getHours();
if(Horas < 10){
Horas = "0"+Horas;
}
var Minutos = Hoje.getMinutes();
if(Minutos < 10){
Minutos = "0"+Minutos;
}
var Segundos = Hoje.getSeconds();
if(Segundos < 10){
Segundos = "0"+Segundos;
}
Elem.innerHTML = Horas+":"+Minutos+":"+Segundos;
}
window.setInterval("Horario()",1000);
</SCRIPT>
If you don’t want to leave the code on index, where do you want to put it? In a separate Javascript file? And why do you say it didn’t work? Error? Which?
– Woss
I want to use it in separate javascript. When I put it like that in js, it appears error saying that it is missing a statement and at the beginning it says that it expects a new line or with point-and-comma. I want to call this javascript function by index to appear at the top of the html page
– Fábio Alves
Has a
<!--
within the tag of<script>
that makes it not work. Now you can do all this much more organized and short– Isac
Oh yes Isac, I took that <!-- but still gave error. As it would be shorter and organized. I found some here, but when I play pro html, it does not pull formatting I want and also very extensive.
– Fábio Alves