Ir para conteúdo

POWERED BY:

Arquivado

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

danielswater

submit com imagem ao invez de botao

Recommended Posts

fala pessoal

e o seguinte, estou tentando fazer uma validação de um campo de email, so que ao invez do botao, eu coloquei uma imagem

so que essa porcaria nao valida

 

se eu tiro a imagem e coloco um botao normal funciona normal, so que com imagem nao

 

segue os cod:

 

<input name="bt" type="image" id="bt" value="Submit" src="imagens/bt-enviar-cadastro-newsletter-link.png" onclick="ValidaEmail()" />

Compartilhar este post


Link para o post
Compartilhar em outros sites

não dispare no onclick do botão, mas sim no onsubmit do formulário.

Compartilhar este post


Link para o post
Compartilhar em outros sites

não dispare no onclick do botão, mas sim no onsubmit do formulário.

 

nem assim nao vai. veja o form:

 

         <form action="cadastra-news.php" method="post" onsubmit="return valida()" >
           <table width="317" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td><label for="email"></label>
                 <input type="text" name="email" id="email" class="form-newsletter" />
                 </td>
             </tr>
             <tr>
               <td></td>
             </tr>
             <tr>
               <td><input name="bt" type="image" id="bt" value="Submit" src="imagens/bt-enviar-cadastro-newsletter-link.png" />

               </td>
             </tr>
           </table>
         </form>

 

e o js:

   <script>
   function valida(){
	if(document.getElementById('email').value == ""){
		alert("Campo Obrigatório");
		return false;
		}
		else{
			return true;
			}
	}
   </script>

Compartilhar este post


Link para o post
Compartilhar em outros sites
 <form action="cadastra-news.php" method="post" name="formulario" onsubmit="return valida()" >
           <table width="317" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td><label for="email"></label>
                 <input type="text" name="email" id="email" class="form-newsletter" />
                 </td>
             </tr>
             <tr>
               <td></td>
             </tr>
             <tr>
               <td><input name="bt" type="image" id="bt" value="Submit" src="imagens/bt-enviar-cadastro-newsletter-link.png" />

               </td>
             </tr>
           </table>
         </form>

<script>
   function valida(){
d = document.formulario;
               if(d.email.value == ""){
                       alert("Campo Obrigatório");
                       return false;
                       }
                       else{
                               return true;
                           }
               }
   </script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, eu testei o seu código aqui:

          <form action="cadastra-news.php" method="post" onsubmit="return valida()" >
           <table width="317" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td><label for="email"></label>
                 <input type="text" name="email" id="email" class="form-newsletter" />
                 </td>
             </tr>
             <tr>
               <td></td>
             </tr>
             <tr>
               <td><input name="bt" type="image" id="bt" value="Submit" src="imagens/bt-enviar-cadastro-newsletter-link.png" />

               </td>
             </tr>
           </table>
         </form>


<script type="text/javascript">
   function valida()
   {
	if(document.getElementById('email').value == "")
	{
		alert("Campo Obrigatório");
		return false;
	}
	else
	{
		return true;
	}
}
</script>

e está perfeito.

 

tem mais algum outro js nesse documento ?

aperte Ctrl+Shift+J e verifique se tem algum erro no console.

Compartilhar este post


Link para o post
Compartilhar em outros sites

nao funcionou

Funciona sim acho que é você que não está sabendo onde colocar o código veja se essa página não funciona, crie um novo html com um nome qualquer e execute no seu browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Teste</title>
<script type="text/javascript">
   function valida(){
d = document.formulario;
               if(d.email.value == ""){
                       alert("Campo Obrigatório");
                       return false;
                       }
                       else{
                               return true;
                           }
               }
</script>
</head>

<body>
<form action="cadastra-news.php" method="post" name="formulario" onsubmit="return valida()" >
           <table width="317" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td><label for="email"></label>
                 <input type="email" name="email" id="email" class="form-newsletter" />
                 </td>
             </tr>
             <tr>
               <td></td>
             </tr>
             <tr>
               <td><input name="bt" type="image" id="bt" value="Submit" src="imagens/bt-enviar-cadastro-newsletter-link.png" />

               </td>
             </tr>
           </table>
</form>
</body>
</html>

 

Lembre-se que você não pode digitar nada no campo input pois no java script está dando a condição se o campo e-mail está vazio então abra o alert.

espero ajudar

Até +

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.