Foros del Web » Programando para Internet » Javascript »

¿Cuál es mi error?

Estas en el tema de ¿Cuál es mi error? en el foro de Javascript en Foros del Web. Estoy tratando de validad este formulario. Valida bien, pero no me redirecciona! ¿Que hago mal? <html> <head> <!-- Copiar dentro del tag HEAD --> <script ...
  #1 (permalink)  
Antiguo 27/12/2009, 09:56
 
Fecha de Ingreso: julio-2009
Mensajes: 15
Antigüedad: 14 años, 9 meses
Puntos: 0
¿Cuál es mi error?

Estoy tratando de validad este formulario.
Valida bien, pero no me redirecciona!
¿Que hago mal?

<html>
<head>
<!-- Copiar dentro del tag HEAD -->
<script LANGUAGE="JavaScript">

function Validar(form)
{
var filter = /^[a-z0-9_\-\.\[\]\(\)]+$/i;

if (!filter.test(form.Nombre.value)){ alert('invalido!');
form.Nombre.focus(); return; }

if (form.Usuario.value == "" || !filter.test(form.Usuario.value))
{ alert("Por favor ingrese su usuario correctamente"); form.Usuario.focus(); return; }

if (form.Contrasenia.value == "" || !filter.test(form.Contrasenia.value))
{ alert("Por favor ingrese su contraseña correctamente"); form.Contrasenia.focus(); return; }

if (form.Contrasenia2.value == "" || !filter.test(form.Contrasenia2.value))
{ alert("Por favor ingrese su repite contraseña correctamente"); form.Contrasenia2.focus(); return; }

if (form.Contrasenia.value != form.Contrasenia2.value)
{ alert("Las cantrseñas no coinciden"); form.Contrasenia.focus(); return; }

if (form.Nombre.value == "" || !filter.test(form.Nombre.value))
{ alert("Por favor ingrese su nombre correctamente"); form.Nombre.focus(); return; }

if (form.Email.value == "")
{ alert("Por favor ingrese su email correctamente"); form.Email.focus(); return; }

if (form.FechaNacdd.value == "" || !filter.test(form.FechaNacdd.value))
{ alert("Por favor ingrese su día de nacimiento correctamente"); form.FechaNacdd.focus(); return; }

if (form.FechaNacmm.value == "" || !filter.test(form.FechaNacmm.value))
{ alert("Por favor ingrese su mes de nacimiento correctamente"); form.FechaNacmm.focus(); return; }

if (form.FechaNacaa.value == "" || !filter.test(form.FechaNacaa.value))
{ alert("Por favor ingrese su año de nacimiento correctamente"); form.FechaNacaa.focus(); return; }

if (form.Apellido.value == "" || !filter.test(form.Apellido.value))
{ alert("Por favor ingrese su apellido correctamente"); form.Apellido.focus(); return; }

if (isNaN(form.FechaNacdd.value) == true || isNaN(form.FechaNacmm.value) == true ||
isNaN(form.FechaNacaa.value) == true)
{ alert("Fecha de nacimiento inválida"); form.FechaNacdd.focus(); return; }

if (form.FechaNacdd.value.length != 2 ||
form.FechaNacdd.value > 31 || form.FechaNacdd.value == 00)
{ alert('Día de la fecha de nacimiento inválida');
form.FechaNacdd.focus(); return true; }

if (form.FechaNacmm.value.length != 2 || form.FechaNacmm.value > 12 ||
form.FechaNacmm.value == 00)
{ alert('Mes de la fecha de nacimiento inválida');
form.FechaNacmm.focus(); return true; }

if (form.FechaNacaa.value.length != 4 || form.FechaNacaa.value > 2010 ||
form.FechaNacaa.value < 1900)
{ alert('Año de la fecha de nacimiento inválida');
form.FechaNacaa.focus(); return true; }

if (form.Pais.value == "" || !filter.test(form.Pais.value))
{ alert("Por favor ingrese su número de pais correctamente"); form.Pais.focus(); return; }

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

if (form.Fax.value == "" || !filter.test(form.Fax.value))
{ alert("Por favor ingrese su fax correctamente"); form.Fax.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();
}

</script>
<title>Registrarse</title>
</head>

<body>
<h1>Registrarse</h1>
<!-- Copiar dentro del tag BODY -->
<form METHOD="get" ACTION="crea_user.php">
<div align="center"><center><table border="0" width="100%">
<tr>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>Usuario</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Usuario"
size="20"></font></td>
<td align="right"><div align="right"><p><font face="Arial" color="#000000"><small>Contresaña</small></font></td>
<td><font color="#FFFFFF" face="Arial"><input type="password" name="Contrasenia"
size="20"></font></td>
</tr>
<tr>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>Repite Contraseña</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="password" name="Contrasenia2"
size="20"></font></td>
<td width="20%" align="right"><div align="right"><p><font face="Arial" color="#000000"><small>Nombre</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Nombre"
size="20"></font></td>
</tr>
<tr>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>Apellido</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Apellido"
size="20"></font></td>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>Fecha de Nacimiento</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input MAXLENGTH="2" type="text" name="FechaNacdd"
size="2">/<input MAXLENGTH="2" type="text" name="FechaNacmm"
size="2">/<input MAXLENGTH="4" type="text" name="FechaNacaa"
size="2">/</font></td>
</tr>
<tr>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>(*) Pais</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Pais"
size="20"></font></td>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>E-mail</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Email"
size="20"></font></td>
</tr>
<tr>
<td width="20%" align="right"><font face="Arial" color="#000000"><small>Teléfono</small></font></td>
<td width="30%"><font color="#FFFFFF" face="Arial"><input type="text" name="Telefono"
size="20"></font></td>
<td width="20%" align="right"></td>
<td width="30%"></td>
</tr>
<tr>
<td width="20%" align="right"></td>
<td width="30%"></td>
<td width="20%" align="right"></td>
<td width="30%"></td>
</tr>
<tr>
<td width="100%" align="center" colspan="4"><div align="center"><center><table border="0"
width="100%" cellspacing="15" cellpadding="0">
<tr>
<td width="100%"><div align="center"><center><p><font face="Arial" color="#000000"><small><input
TYPE="button" VALUE="Enviar" onClick="Validar(this.form)"><input TYPE="reset"></small></font></td>
</tr>
</table>
</center></div></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
  #2 (permalink)  
Antiguo 27/12/2009, 12:24
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: ¿Cuál es mi error?

en el codigo de validacion se esta validando un campo adicional que no existe en el formulario. me refiero al bloque
Código:
if (form.Fax.value == "" || !filter.test(form.Fax.value))
{ alert("Por favor ingrese su fax correctamente"); form.Fax.focus(); return; }
elimina ese codigo y el resto funcionara. por otra parte, la validacion deberias hacerla en el evento onsubmit de <form> y no en el evento onclick del boton. si te decides hacerlo asi, tambien tienes que cambiar el tipo de boton por submit.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #3 (permalink)  
Antiguo 27/12/2009, 20:06
 
Fecha de Ingreso: julio-2009
Mensajes: 15
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: ¿Cuál es mi error?

Gracias por responder!
Cambié todo lo que me dijiste pero agún sigue sin hacer nada. Si completo los campos mal, me sale error; si los dejo vacíos me sale que los complete.
Pero cuando los lleno todos correctamente no hace nada. El formulario no redirecciona a crea_user.php

¡Me estoy volviendo loca!
  #4 (permalink)  
Antiguo 27/12/2009, 20:09
 
Fecha de Ingreso: julio-2009
Mensajes: 15
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: ¿Cuál es mi error?

Ya esta resuelto.
Había olvidado de cambiar el tipo de boton por submit!

Gracias!!!!!!!!!!!
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 03:16.