Alguém saberia o porque meu javascript parou de funcionar do nada???, uso o netbeans 6.9.1, os navegadores firefox 3.6.13 e ie8… ambos com javascript habilitado, será que fiz alguma merda no código?
index.jsp
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Maior site do Brasil</title>
<script type="text/javascript" src="validaCampos.js"></script>
<script type="text/javascript" src="mascaraNavegador.js"></script>
<script type="text/javascript">
window.onload = function()
{
document.getElementById("nome").onblur = function(evt)
{
validaNome(this,document.getElementById('nome_ajuda'));
}
document.getElementById("nome").maxlength = "8";
document.getElementById("cpf").onblur = function(evt)
{
validaCPF(this,document.getElementById('cpf_ajuda'));
}
document.getElementById("cpf").maxlength = "11";
document.getElementById("cpf").onkeypress = function(evt)
{
mascara(this,soNumeros);
}
document.getElementById("email").onblur = function(evt)
{
validaEmail(this,document.getElementById('email_ajuda'));
}
document.getElementById("cadastrar").onclick = function(evt)
{
le(this.form);
if(document.getElementById("email").value != document.getElementById("email2").value)
{
document.getElementById('email_ajuda').innerHTML = "Emails diferente";
document.getElementById('email2_ajuda').innerHTML = "Emails diferente";
}
else
{
alert('igual');
}
}
}
function le(theForm)
{
alert('cpf é: ' + theForm["cpf"].value);
}
</script>
</head>
<body>
<p>
<img id="logo" src="imagens/aluga_01.jpg" alt="Logo Principal" />
</p>
<form action="resultado.html" method="post">
<div>
Nome completo:
<input name="nome" type="text" size="81" />
<span id="nome_ajuda"></span>
</div>
<div>
CPF(só números):
<input id="cpf" name="cpf" type="text" size="12" />
<span id="cpf_ajuda"></span>
</div>
<div>
Data de nascimento:
<input name="nascimento" type="text" size="10" />
<span id="nascimento_ajuda"></span>
</div>
<div>
Crie uma senha:
<input name="senha" type="password" size="15" />
<span id="senha_ajuda"></span>
</div>
<div>
Digite a senha novamente:
<input name="senha2" type="password" size="15" />
<span id="senha2_ajuda"></span>
</div>
<div>
Cidade:
<input id="cidade" name="cidade" type="text" size="32" />
<span id="cidade_ajuda"></span>
</div>
<div>
Telefone:
<input name="telefone" type="text" size="12" />
<span id="telefone_ajuda"></span>
</div>
<div>
Email:
<input id="email" name="email" type="text" size="32" />
<span id="email_ajuda"></span>
</div>
<div>
Confirmar email:
<input id="email2" name="email2" type="text" size="32" />
<span id="email2_ajuda"></span>
<br />
</div>
<div>
<input id="cadastrar" type="button" value="Cadastrar" />
</div>
</form>
</body>
</html>
validacampos.js
[code]function verificaCampovazio(campoTexto,ajuda)
{
if (campoTexto.value.length == 0)
{
ajuda.innerHTML = “Campo obrigatório.”;
return false;
}
else
{
ajuda.innerHTML = “”;
return true;
}
}
function validaNome(campoTexto,ajuda)
{
if (campoTexto.value.length == 0 || campoTexto.value.length < 8)
{
ajuda.innerHTML = “Preencha o campo nome corretamente.”;
return false;
}
else
{
ajuda.innerHTML = “”;
return true;
}
}
function validaEmail(email, ajuda)
{
var er = new RegExp(/^[A-Za-z0-9_-.]+@[A-Za-z0-9_-.]{2,}.[A-Za-z0-9]{2,}(.[A-Za-z0-9])?/);
if(typeof(email) == “string”)
{
if(email.length == 0 || email == null)
{
ajuda.innerHTML = "Campo email é obrigatório.";
return false;
}
else
{
if(er.test(email))
{
ajuda.innerHTML = "";
return true;
}
else
{
ajuda.innerHTML = "Email inválido.";
return false;
}
}
}
if(typeof(email) == "object")
{
if(email.value.length == 0 || email.value == null)
{
ajuda.innerHTML = "Campo email é obrigatório.";
return false;
}
else
{
if(er.test(email.value))
{
ajuda.innerHTML = "";
return true;
}
else
{
ajuda.innerHTML = "Email inválido.";
return false;
}
}
}
return false;
}
function validaCPF(num, ajuda)
{
var CPF = num.value; // Recebe o valor digitado no campo
if(CPF.length == 0 || CPF == null)
{
ajuda.innerHTML = "Campo CPF é obrigatório.";
return false;
}
CPF = CPF.replace(/./g, “”);
CPF = CPF.replace(/-/g, “”);
CPF = CPF.replace(/_/g, “”);
// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++)
{
DIGITO[I] = CPF.substr( I, 1);
}
// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
for (I=0; I<=8; I++)
{
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[9] = SOMA % 11;
if (DIGITO[9] < 2)
{
DIGITO[9] = 0;
}
else
{
DIGITO[9] = 11 - DIGITO[9];
}
// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
for (I=0; I<=9; I++)
{
SOMA = SOMA + DIGITO[I] * POSICAO;
POSICAO = POSICAO - 1;
}
DIGITO[10] = SOMA % 11;
if (DIGITO[10] < 2)
{
DIGITO[10] = 0;
}
else
{
DIGITO[10] = 11 - DIGITO[10];
}
// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
if (DV != DV_INFORMADO)
{
ajuda.innerHTML = “CPF inválido.”;
return false;
}
else
{
ajuda.innerHTML = “”;
return true;
}
}[/code]
mascaraNavegador.js
[code]function mascara(o,f)
{
v_obj=o
v_fun=f
setTimeout(“execmascara()”,1)
}
function execmascara()
{
v_obj.value=v_fun(v_obj.value)
}
function soNumeros(v)
{
return v.replace(/\D/g,"")
}[/code]