Ir para conteúdo

POWERED BY:

Arquivado

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

jonata

Problema com validação de form.

Recommended Posts

<html><head><script Language="JavaScript">function Valida(){  if (document.cadastro.email.value == ""){		  		  document.cadastro.email.style.background = "D5D5D5"	  return false;  }  if (document.cadastro.senha.value == ""){		  		  document.cadastro.senha.style.background = "D5D5D5"	  return false;  }}</script></head><body><form name=cadastro method=post action="http://www.scriptbrasil.com.br">Email: <input type=text name=email><br>Senha: <input type=text name=senha><br><input type=submit onclick="return Valida()"></form></body></html>

Onde está o erro? Pois só fica colorido o 1º campo!

 

Regras do Fórum iMasters

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sempre que uma função em Javascript encontra um RETURN ele devolve o resultado e aborta o escopo. Utiliza uma variável para armazenar o status de retorno, dessa forma:

<html><head><script Language="JavaScript">	function Valida()	{		var status = true;		if (document.getElementById('email').value.length == 0){			document.getElementById('email').style.background = "D5D5D5"			status = false;		}		if (document.getElementById('senha').value.length == 0){		  			document.getElementById('senha').style.background = "D5D5D5"			status = false;		}		return status;	}</script></head><body><form name="cadastro" method="post" action="http://www.scriptbrasil.com.br">Email: <input type="text" name="email" id="email"><br>Senha: <input type="text" name="senha" id="senha"><br><input type="submit" onclick="return Valida()"></form></body></html>
OK..!!?? T+...

Compartilhar este post


Link para o post
Compartilhar em outros sites

não manjo nada de javascript mas esa eu entendi!!!!!muito obrigado1bem minha página é em php não tem nenhum problema não ? be se eu quiser além de coloriri o campo apareça uma imagem ao lado dele?

Compartilhar este post


Link para o post
Compartilhar em outros sites

O lance de ser em PHP não atrapalha em nada. Em relação a imagem ao lado do campo é bem fácil, porém, ja que você vai precisar de mais efeitos em Javascript, sugiro que estude e aprenda um pouco mais da linguagem.Conforme suas dúvidas durante o desenvolvimento forem surgindo você vai postando e a galera te ajuda.OK..!!?? T+...

Compartilhar este post


Link para o post
Compartilhar em outros sites

eu colquei assim:

 

 

<script Language="JavaScript">	function Valida()	{		var status = true;		if (document.getElementById('nome').value.length == 0){			document.getElementById('nome').style.background = "#FFFFCC"			status = false;		}		if (document.getElementById('sexo').value == ""){		  			document.getElementById('sexo').style.background = "#FFFFCC"			status = false;		} if (document.getElementById('d1').value.length == 0){		  			document.getElementById('d1').style.background = "#FFFFCC"			status = false;		}		 if (document.getElementById('d2').value.length == 0){		  			document.getElementById('d2').style.background = "#FFFFCC"			status = false;		}				 if (document.getElementById('d3').value.length == 0){		  			document.getElementById('d3').style.background = "#FFFFCC"			status = false;		}				 if (document.getElementById('ano_letivo').value== ""){		  			document.getElementById('ano_letivo').style.background = "#FFFFCC"			status = false;		}				 if (document.getElementById('end').value.length == 0){		  			document.getElementById('end').style.background = "#FFFFCC"			status = false;		}		 if (document.getElementById('n').value.length == 0){		  			document.getElementById('n').style.background = "#FFFFCC"			status = false;		}				 if (document.getElementById('bairro').value.length == 0){		  			document.getElementById('bairro').style.background = "#FFFFCC"			status = false;		}				 if (document.getElementById('cep').value.length == 0){		  			document.getElementById('cep').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('cidade').value.length == 0){		  			document.getElementById('cidade').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('estado').value.length == 0){		  			document.getElementById('estado').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('cep').value.length == 0){		  			document.getElementById('cep').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('tel2').value.length == 0){		  			document.getElementById('tel2').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('respon').value.length == 0){		  			document.getElementById('respon').style.background = "#FFFFCC"			status = false;		}		if (document.getElementById('cpf').value.length == 0){		  			document.getElementById('cpf').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('rg').value.length == 0){		  			document.getElementById('rg').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('email').value.length==0){		  			document.getElementById('email').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('loguin').value.length==0 ){		  			document.getElementById('loguin').style.background = "#FFFFCC"			status = false;		}				if (document.getElementById('senha').value.length== 0){		  			document.getElementById('senha').style.background = "#FFFFCC"			status = false;		}				return status;	}</script>

 

TESTANDO >>>tem dois menus lista: sempre que eu clico apareçe em todos menos nos 2 ultimos campos

 

 

 

 

os campos que são menu(lista) são o: ano_letivo, sexo!

 

 

 

 

 

problema: mesmo que eu preencha todos o submit nõ funfa!!!!! é como se estivesse bloqueado!

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.