Foros del Web » Programando para Internet » Javascript »

Formulario q no se envie con enter!

Estas en el tema de Formulario q no se envie con enter! en el foro de Javascript en Foros del Web. Hola a todos! Tengo un formulario con validaciones. Si aprieto en el boton enviar sin haber llenado los campos obligatorios, me salta un cartelito que ...
  #1 (permalink)  
Antiguo 09/05/2005, 14:03
Avatar de Il Dody  
Fecha de Ingreso: abril-2005
Ubicación: Argentina
Mensajes: 88
Antigüedad: 19 años
Puntos: 1
Pregunta Formulario q no se envie con enter!

Hola a todos!
Tengo un formulario con validaciones. Si aprieto en el boton enviar sin haber llenado los campos obligatorios, me salta un cartelito que dice: "por favor, complete los datos requeridos" pero al cliquear en ese cartelito en aceptar, el cartelito desaparece y el formulario se envia automatizamente!!!

Como puedo hacer para q esto no ocurra???

Muchas gracias!!!!!!!!!!
__________________
IL DODY
  #2 (permalink)  
Antiguo 09/05/2005, 18:21
Avatar de monoswim
$moderador{'Esteban'}
 
Fecha de Ingreso: febrero-2002
Ubicación: Buenos Aires - Argentina
Mensajes: 8.762
Antigüedad: 22 años, 2 meses
Puntos: 90
Es porque cuando evaluas el formulario no colocás el return false para que no se ejecute el action del form...

probá con

alert('msg de error');
return false;

Saludos
__________________
Esteban Quintana
  #3 (permalink)  
Antiguo 10/05/2005, 01:32
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
vámonos a Javascript!
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.
  #4 (permalink)  
Antiguo 10/05/2005, 06:18
Avatar de Il Dody  
Fecha de Ingreso: abril-2005
Ubicación: Argentina
Mensajes: 88
Antigüedad: 19 años
Puntos: 1
Gracias por la respuesta Monoswim!
Probé con lo q me dijiste pero no me funciona. Supongo q se debe a que no lo estoy colocando como corresponde. Te paso todo el javascript asi ves donde lo coloque, a ver si lo hice bien!
Muchisimas gracias!


<script>
function check(){
document.formul.enviar.value = "Procesando Formulario";
document.formul.enviar.disabled = true;
document.formul.submit();
}
var patron = new Array(2,2,4)
var patron2 = new Array(1,3,3,3,3)
function mascara(d,sep,pat,nums){
if(d.valant != d.value){
val = d.value
largo = val.length
val = val.split(sep)
val2 = ''
for(r=0;r<val.length;r++){
val2 += val[r]
}
if(nums){
for(z=0;z<val2.length;z++){
if(isNaN(val2.charAt(z))){
letra = new RegExp(val2.charAt(z),"g")
val2 = val2.replace(letra,"")
}
}
}
val = ''
val3 = new Array()
for(s=0; s<pat.length; s++){
val3[s] = val2.substring(0,pat[s])
val2 = val2.substr(pat[s])
}
for(q=0;q<val3.length; q++){
if(q ==0){
val = val3[q]
}
else{
if(val3[q] != ""){
val += sep + val3[q]
}
}
}
d.value = val
d.valant = val
}
}
function Validar(form)
{
if (form.Nombre.value == "")
{ alert("Por favor ingrese su nombre"); form.Nombre.focus(); return; }

if (form.Email.value == "")
{ alert("Por favor ingrese su dirección de e-mail"); form.Email.focus(); return; }

if (form.Domicilio.value == "")
{ alert("Por favor ingrese su domicilio"); form.Domicilio.focus(); return; }

if (form.Telefono.value == "")
{ alert("Por favor ingrese su número de teléfono"); form.Telefono.focus(); return; }

if (form.Email.value.indexOf('@', 0) == -1 ||
form.Email.value.indexOf('.', 0) == -1)
{ alert("Dirección de e-mail inválida"); form.Email.focus(); return; }

form.submit();
alert('msg de error');
return false;
}
</script>
__________________
IL DODY
  #5 (permalink)  
Antiguo 10/05/2005, 07:19
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Hola Il Dody

El formulario tendrías que ponerlo así:

<form onsubmit="return check()" />

y cuando no pase alguna de las validaciones tienes que devolver false. Por ejemplo:

if (form.Nombre.value == "")
{ alert("Por favor ingrese su nombre"); form.Nombre.focus(); return false; }

Espero que te sirva. Saludos,
  #6 (permalink)  
Antiguo 10/05/2005, 08:48
Avatar de Il Dody  
Fecha de Ingreso: abril-2005
Ubicación: Argentina
Mensajes: 88
Antigüedad: 19 años
Puntos: 1
Gracias JavierB por tu ayuda!!!!!!
Pero todavia no logro que funcione correctamente ya q me sigue haciendo lo mismo. Se envia cuando le doy aceptar a algun mensaje de error!
A continuación pego todo el dodigo a ver si alguién puede encontrar el error!
Muchas gracias!!!


<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<TITLE>Hola</TITLE>
<script>
function check(){
document.formul.enviar.value = "Procesando Formulario";
document.formul.enviar.disabled = true;
document.formul.submit();
}
var patron = new Array(2,2,4)
var patron2 = new Array(1,3,3,3,3)
function mascara(d,sep,pat,nums){
if(d.valant != d.value){
val = d.value
largo = val.length
val = val.split(sep)
val2 = ''
for(r=0;r<val.length;r++){
val2 += val[r]
}
if(nums){
for(z=0;z<val2.length;z++){
if(isNaN(val2.charAt(z))){
letra = new RegExp(val2.charAt(z),"g")
val2 = val2.replace(letra,"")
}
}
}
val = ''
val3 = new Array()
for(s=0; s<pat.length; s++){
val3[s] = val2.substring(0,pat[s])
val2 = val2.substr(pat[s])
}
for(q=0;q<val3.length; q++){
if(q ==0){
val = val3[q]
}
else{
if(val3[q] != ""){
val += sep + val3[q]
}
}
}
d.value = val
d.valant = val
}
}
function Validar(form)
{
if (form.Nombre.value == "")
{ alert("Por favor ingrese su nombre"); form.Nombre.focus(); return false; }

if (form.Email.value == "")
{ alert("Por favor ingrese su dirección de e-mail"); form.Email.focus(); return false; }

if (form.Domicilio.value == "")
{ alert("Por favor ingrese su domicilio"); form.Domicilio.focus(); return false; }

if (form.Telefono.value == "")
{ alert("Por favor ingrese su número de teléfono"); form.Telefono.focus(); return false; }

if (form.Email.value.indexOf('@', 0) == -1 ||
form.Email.value.indexOf('.', 0) == -1)
{ alert("Dirección de e-mail inválida"); form.Email.focus(); return false; }

form.submit();
}
</script>
</HEAD>
<BODY>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="80" valign="top"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="70">
<param name="movie" value="cabezal_pop.swf">
<param name="quality" value="high">
<embed src="cabezal_pop.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="70"></embed>
</object></td>
</tr>
<tr>
<td><div align="center"> </div> <table width="98%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#003366" bgcolor="#F0FBFF">
<tr>
<td>
<form action='formulario.php' method='post' enctype="multipart/form-data" name='formulario' target='_self' id='formulario' onsubmit="return check()" />
<table width="89%" border="0" align="center">
<tr bgcolor="#003366">
<td height="25" colspan="3" class="txt-bold style6"><div align="center">DATOS PERSONALES</div></td>
</tr>
<tr>
<td width="105" class="style5">Nombre*</td>
<td colspan="2" class="style5"><input name="Nombre" type="text" id="Nombre" size="30"></td>
</tr>
<tr>
<td class="style5">Apellido*</td>
<td colspan="2" class="style5"><input name="Apellido" type="text" id="Apellido" size="30"></td>
</tr>
<tr>
<td class="style5">Fecha de nacimiento*</td>
<td width="72" class="style5"><input name="fecha" type="text" onkeyup="mascara(this,'/',patron,true)" size="12" maxlength="10" /></td>
<td width="154" class="style5">dd/mm/aaaa</td>
</tr>
<tr>
<td class="style5">Domicilio</td>
<td colspan="2" class="style5"><input name="Domicilio" type="text" id="Domicilio" size="30"></td>
</tr>
<tr>
<td class="style5">C&oacute;digo Postal </td>
<td colspan="2" class="style5"><input name="CP" type="text" id="CP" size="30"></td>
</tr>
<tr>
<td class="style5">Ciudad*</td>
<td colspan="2" class="style5"><input name="Ciudad" type="text" id="Ciudad" size="30"></td>
</tr>
<tr>
<td class="style5">Pais*</td>
<td colspan="2" class="style5"><input name="Pais" type="text" id="Pais" size="30"></td>
</tr>
<tr>
<td class="style5">Tel&eacute;fono*</td>
<td colspan="2" class="style5"><input name="Telefono" type="text" id="Telefono" size="30"></td>
</tr>
<tr>
<td class="style5">E-mail*</td>
<td colspan="2" class="style5"><input name="Email" type="text" id="Email" size="30"></td>
</tr>
<tr>
<td colspan="3" class="txt">&nbsp;</td>
</tr>
<tr bgcolor="#003366">
<td height="25" colspan="3" class="txt"> <div align="center"><strong class="style6">CURRICULUM VITAE</strong></div></td>
</tr>
<tr>
<td colspan="3" class="style5"> (Adjunte el archivo con un tama&ntilde;o menor a 260 kb. en formato .PDF, .DOC, .RTF o .TXT) </td>
</tr>
<tr>
<td colspan="3" class="txt"><span class="txt style6"><input type='file' name='archivo1' id='archivo1'></td>
</tr>
<tr>
<td colspan="3" class="txt">&nbsp;</td>
</tr>
<tr bgcolor="#003366" class="txt">
<td height="25" colspan="3" class="txt"><div align="center"><span class="style6"><strong>COMENTARIOS</strong></span></div></td>
</tr>
<tr>
<td colspan="3"><FONT
face=Arial size=-1>
<TEXTAREA name=Comentarios cols=39 rows=5 id="Comentarios"></TEXTAREA>
</FONT></td>
</tr>
</table>
<table width="89%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="64%" height="1"><img src="images/px_azul.gif" width="100%" height="1"></td>
<td width="26%"><div align="center">
<input name="boton" type="image" id="boton" src="images/ima_enviar.gif" width="119" border="0" onClick="Validar(this.form)">
</div></td>
<td width="10%"><img src="images/px_azul.gif" width="100%" height="1"></td>
</tr>
</table>
<div align="center"></div>
</form></td>
</tr>
</table> </td>
</tr>
<tr>
<td height="27" valign="bottom"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="17">
<param name="movie" value="pie_pop.swf">
<param name="quality" value="high">
<embed src="pie_pop.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="17"></embed>
</object></td>
</tr></table>
</BODY>
</HTML>
__________________
IL DODY
  #7 (permalink)  
Antiguo 10/05/2005, 09:16
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Hola de nuevo. A ver si esta vez doy con ello:

En la imágen que usas para enviar el formulario quita el evento onclick:

<input name="boton" type="image" id="boton" src="images/ima_enviar.gif" width="119" border="0">

Y en el formulario en lugar de poner onsubmit="return check()", como te dije en el anterior mensaje, pon onsubmit="return Validar(this)"

Saludos,
  #8 (permalink)  
Antiguo 10/05/2005, 09:28
Avatar de Il Dody  
Fecha de Ingreso: abril-2005
Ubicación: Argentina
Mensajes: 88
Antigüedad: 19 años
Puntos: 1
JavierB :::::::> SOS UN CAPO!!!!
Problema solucionado!
Muchisimas gracias!! Esto ya me habia sacado canas verdes!!
__________________
IL DODY
  #9 (permalink)  
Antiguo 10/05/2005, 09:49
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Sabía que al final lo conseguirías Me alegro de que lo hayas solucionado. Hasta otra
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 21:25.