Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ronaldo_calado

Problema com javascript

Recommended Posts

tenho um script simples de data no meu site que ta dando erro quando eu tento validar no w3c?? oq ta errado, tenho q colocar dentro d um arquivo .js e chamar, se tiver q ser assim, como farei pra ele chamar e mostrar a data???

alguem pode me ajudar??

o script é esse:

<script language="javascript" type="text/javascript">

 

document.write("<font color='#666666' size='1' face='tahoma'>")

var mydate=new Date()

var year=mydate.getYear()

if (year<2000)

year += (year < 1900) ? 1900 : 0

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym<10)

daym="0"+daym

var cidade="São Luís"

var dayarray=new Array("domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado")

var montharray=new Array(" de Janeiro de "," de Fevereiro de "," de Março de ","de Abril de ","de Maio de ","de Junho de","de Julho de ","de Agosto de ","de Setembro de "," de Outubro de "," de Novembro de "," de Dezembro de ")

document.write(" "+cidade+", "+dayarray[day]+", "+daym+" "+montharray[month]+year+" ")

document.write("</font>")

</script>

E esses são os problemas:

 

Line 62 column 60: document type does not allow element "font" here.

document.write("<font color='#666666' size='1' face='tahoma'>")

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

 

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

 

Warning Line 65 column 8: character "<" is the first character of a delimiter but occurred as data.

if (year<2000)

This message may appear in several cases:

 

You tried to include the "<" character in your page: you should escape it as "<"

You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.

Another possibility is that you forgot to close quotes in a previous tag.

 

 

Warning Line 66 column 14: character "<" is the first character of a delimiter but occurred as data.

year += (year < 1900) ? 1900 : 0

 

 

Warning Line 70 column 8: character "<" is the first character of a delimiter but occurred as data.

if (daym<10)

 

 

Error Line 195 column 77: there is no attribute "onSubmit".

..." method="post" target="votar" onSubmit="java script:enq();">

You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

 

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

 

How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

 

Error Line 209 column 74: there is no attribute "onClick".

...r" src="imagens/submit_button.jpg" onClick="Submeter();" />

 

Esses ultimos erros são devido a informações que to passando na hra d submeter o formulario, pra ele abrir num pop-up, oq eu devo fazer pra corrigir esses erros??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Primeiro troque aquele <font...> e </font> por:

<span style="font:11px Tahoma, Arial, Helvetica, sans-serif; color:#666"> e </span>

 

Vamos ver se diminui os erros...

[]s

Os erros não diminuiram, e deu esse erro:

 

Line 62 column 88: document type does not allow element "span" here.

...l, Helvetica, sans-serif; color:#666'>")

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

 

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

 

Os problemas com javascript eu não sei responder, os outros todos eu ja resolvi, to precisando d ajuda com esses javas!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa, então, o problema é que tem HTML dentro do seu JavaScript.

 

Tive este problema outro dia e resolvi "escapando" as aspas e as barras. Bom, funcionou!

 

Por exemplo:

 

acronymSample = '<acronym title=\"Transcricao do Acronimo\" lang=\"pt-br\">ACRONYM<\/acronym>';

No seu caso:

 

<script language="javascript" type="text/javascript">document.write("<span class=\"minha_fonte\">")var mydate=new Date()var year=mydate.getYear()if (year<2000)year += (year < 1900) ? 1900 : 0var day=mydate.getDay()var month=mydate.getMonth()var daym=mydate.getDate()if (daym<10)daym="0"+daymvar cidade="São Luís"var dayarray=new Array("domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado")var montharray=new Array(" de Janeiro de "," de Fevereiro de "," de Março de ","de Abril de ","de Maio de ","de Junho de","de Julho de ","de Agosto de ","de Setembro de "," de Outubro de "," de Novembro de "," de Dezembro de ")document.write(" "+cidade+", "+dayarray[day]+", "+daym+" "+montharray[month]+year+" ")document.write("<\/span>")</script>

Coloco em sua folha de estilo:

 

.minha_fonte {font: 11px Tahoma, Arial, Helvetica, sans-serif; color:#666;}

Nomeie para o que você quiser e tente fazer a estrutura do seu site sem HTML de estilo, só de estrutura! :D

 

Acredito que isso resolva o seu problema.

 

Porém, é sempre indicado, se você entende bem de programação, utilizar funções e objetos que evitem essa prática no corpo da página, assim você separa conteúdo de script e layout sempre!

 

;)

 

Att.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie um arquivo .js com as funções, e na página em questão apenas "chame" a função.Ou utilize o CDATA nos javascripts para que o validador não tente validar o seu código js.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera já resolvi a maioria dos problemas agora só ta faltando resolver a parada do onclick e onsubmit dos formularios, oq eu poderia fazer pra resolver o problema???

 

Essa é a mensagem:

 

Line 197 column 77: there is no attribute "onSubmit".

..." method="post" target="votar" onSubmit="java script:enq();">

You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

 

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

 

How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

 

 

Error Line 211 column 74: there is no attribute "onClick".

...r" src="imagens/submit_button.jpg" onClick="Submeter();" />

 

Oq eu devo fazer??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acho que é simples.você tá tentando usar DOCTYPE Strict no seu documento, mas seu documento não tá seguindo as regras do strict.você pode ver o DOCTYPE lá no começo do seu código.Tente mudar pra um doctype mais básico como HTML 4.01 Transitional.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acho que é simples.

 

você tá tentando usar DOCTYPE Strict no seu documento, mas seu documento não tá seguindo as regras do strict.

 

você pode ver o DOCTYPE lá no começo do seu código.

Tente mudar pra um doctype mais básico como HTML 4.01 Transitional.

O meu DOCTYPE não é Strict, ele ja é Transitional:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

oq pod estar errado pra dar esse problema com onclick e com onsubmit, oq eu posso fazer pra resolver??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faz o seguinte: posta logo o link que fica mais fácil.

 

Valeus..

http://www.adcohatrac.com.br/teste_vdm/vdm_web/

 

esse é o link!!!

 

e esse é a parte do script q ta dando o erro(em negrito):

 

<form action="resul_enquete.php" method="post" target="votar" onSubmit="java script:enq();">

 

<span class="style7">ENQUETE<br />

 

<?

 

include "conecta.php";

 

$comando = mysql_query("SELECT * FROM enquetes WHERE ativo='1'");

 

$linha = mysql_fetch_array($comando);

 

$id_enquete = $linha['id_enquete'];

$pergunta = $linha['pergunta'];

 

?>

 

<input type="hidden" value="<? echo $id_enquete ?>" name="id" />

 

<span class="style10"><? echo $pergunta ?>

<input name="resposta" type="radio" class="style17" value="sim" />SIM

<input name="resposta" type="radio" class="style17" value="nao" />Não <font color="#000000" face="ARIAL">  

<input type="image" value="votar" src="imagens/submit_button.jpg" onClick="Submeter();" />

</font> </span></span>

</form>

Oq fazer???

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não sei se já te falaram isso, mas troque onSubmit por onsubmit, pois XML só aceita atributos completamente em minúsculas.Faça o mesmo com o onclick.Me diga se deu certo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não sei se já te falaram isso, mas troque onSubmit por onsubmit, pois XML só aceita atributos completamente em minúsculas.Faça o mesmo com o onclick.Me diga se deu certo.

Kra, era só isso, valew!!!!consegui a certificação

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.