Foros del Web » Creando para Internet » Diseño web »

validar javascript con el w3c

Estas en el tema de validar javascript con el w3c en el foro de Diseño web en Foros del Web. Hoola a todos, acabo de subscribirme a este foro y quiero pedir perdon por si no lo estoy haciendo bien, no me ha quedado muy ...
  #1 (permalink)  
Antiguo 07/03/2008, 18:01
 
Fecha de Ingreso: marzo-2008
Mensajes: 5
Antigüedad: 16 años, 1 mes
Puntos: 0
Pregunta validar javascript con el w3c

Hoola a todos, acabo de subscribirme a este foro y quiero pedir perdon por si no lo estoy haciendo bien, no me ha quedado muy claro si debía abrir un tema nuevo para mi pregunta o si seguir alguno de los aviertos.s.
Os Cuento, estoy intentando valaidar un javascript en el w3c y me da un error que no entiendo, a ver si me podeis hechar una manita.
El código del javascript es:

<script type="text/javascript" language="JavaScript">
var dt = new Date();
var hr = dt.getHours();
var msg = ((hr<12) ? "Buenos dias" :"Buenas Noches");
msg = ((hr>11)&&(hr<19) ? "Buenas Tardes" : msg);
msg=" <H2> "+msg+" !</H2>";
document.write(msg);
</script>

y el error del validador del w3c es:


Validation Output: 5 Errors
lista de 9 elementos
Warning
Line 38, Column 15: character "<" is the first character of a delimiter but occurred as data. var msg = ((hr <12) ? "Buenos dias" :"Buenas Noches");

This message may appear in several cases:
lista de 3 elementos nivel de encabezado 1
• You tried to include the "<" character in your page: you should escape it as "lt;"
• You used an unescaped ampersand "": this may be valid in some contexts, but it is recommended to use "amp;", which is always safe.
• Another possibility is that you forgot to close quotes in a previous tag.
final de lista nivel de encabezado 1
Warning
Line 39, Column 15: character "" is the first character of a delimiter but occurred as data. msg = ((hr>11) &(hr<19) ? "Buenas Tardes" : msg);

This message may appear in several cases:
lista de 3 elementos nivel de encabezado 1
• You tried to include the "<" character in your page: you should escape it as "lt;"
• You used an unescaped ampersand "": this may be valid in some contexts, but it is recommended to use "amp;", which is always safe.
• Another possibility is that you forgot to close quotes in a previous tag.
final de lista nivel de encabezado 1
Warning
Line 39, Column 16: character "" is the first character of a delimiter but occurred as data. msg = ((hr>11)& &(hr<19) ? "Buenas Tardes" : msg);

This message may appear in several cases:
lista de 3 elementos nivel de encabezado 1
• You tried to include the "<" character in your page: you should escape it as "lt;"
• You used an unescaped ampersand "": this may be valid in some contexts, but it is recommended to use "amp;", which is always safe.
• Another possibility is that you forgot to close quotes in a previous tag.
final de lista nivel de encabezado 1
Warning
Line 39, Column 20: character "<" is the first character of a delimiter but occurred as data. msg = ((hr>11)&(hr <19) ? "Buenas Tardes" : msg);

This message may appear in several cases:
lista de 3 elementos nivel de encabezado 1
• You tried to include the "<" character in your page: you should escape it as "lt;"
• You used an unescaped ampersand "": this may be valid in some contexts, but it is recommended to use "amp;", which is always safe.
• Another possibility is that you forgot to close quotes in a previous tag.
final de lista nivel de encabezado 1
Error
Line 40, Column 10: element "H2" undefined. msg=" <H2 > "+msg+" !</H2>";

You have used the element named above in your document, but the document type you are using does not define an element of that name.
This error is often caused by:
lista de 3 elementos nivel de encabezado 1
• incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the
"<frameset>" element),
• by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect
instead).
• by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case).
final de lista nivel de encabezado 1
Error
Line 38, Column 16: XML Parsing Error: StartTag: invalid element name. var msg = ((hr< 12) ? "Buenos dias" :"Buenas Noches");

Error
Line 39, Column 16: XML Parsing Error: xmlParseEntityRef: no name. msg = ((hr>11)& &(hr<19) ? "Buenas Tardes" : msg);

Error
Line 39, Column 17: XML Parsing Error: xmlParseEntityRef: no name. msg = ((hr>11)& (hr<19) ? "Buenas Tardes" : msg);

Error
Line 39, Column 21: XML Parsing Error: StartTag: invalid element name. msg = ((hr>11)&(hr< 19) ? "Buenas Tardes" : msg);

final de lista

Muchas gracias a quien me pueda ayudar.
  #2 (permalink)  
Antiguo 08/03/2008, 04:06
Avatar de Raulmmmm  
Fecha de Ingreso: marzo-2007
Ubicación: En otro lugar que tú
Mensajes: 1.549
Antigüedad: 17 años, 1 mes
Puntos: 36
Re: validar javascript con el w3c

Me parece que tendrás que comentar el código, sustituir H2 por h2 y cambiar la etiqueta. Quedaría así:
Código HTML:
<script>
<!--
var dt = new Date();
var hr = dt.getHours();
var msg = ((hr<12) ? "Buenos dias" :"Buenas Noches");
msg = ((hr>11)&&(hr<19) ? "Buenas Tardes" : msg);
msg=" <h2> "+msg+" !</h2>";
document.write(msg);
-->
</script> 
Mira a ver si va.
  #3 (permalink)  
Antiguo 08/03/2008, 04:33
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Re: validar javascript con el w3c

Hola jortiz015 y Raulmmmm

La etiqueta script debe ser:

Código:
<script type="text/javascript">
Saludos,
  #4 (permalink)  
Antiguo 08/03/2008, 05:17
Avatar de Raulmmmm  
Fecha de Ingreso: marzo-2007
Ubicación: En otro lugar que tú
Mensajes: 1.549
Antigüedad: 17 años, 1 mes
Puntos: 36
Re: validar javascript con el w3c

Gracias, JavierB, me había confundido con el atributo language, que no se debe poner, ¿no?. Entonces sería así:
Código HTML:
<script type="text/javascript">
<!--
var dt = new Date();
var hr = dt.getHours();
var msg = ((hr<12) ? "Buenos dias" :"Buenas Noches");
msg = ((hr>11)&&(hr<19) ? "Buenas Tardes" : msg);
msg=" <h2> "+msg+" !</h2>";
document.write(msg);
-->
</script> 
  #5 (permalink)  
Antiguo 08/03/2008, 08:08
 
Fecha de Ingreso: marzo-2008
Mensajes: 5
Antigüedad: 16 años, 1 mes
Puntos: 0
Re: validar javascript con el w3c

Hoola, muchas gracias, ya rfunciona perféctamente. Voy ha itnentar validar otros javascript que tengo por aquí.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:35.