Ver Mensaje Individual
  #8 (permalink)  
Antiguo 25/11/2009, 19:02
Wickedalone
 
Fecha de Ingreso: noviembre-2009
Mensajes: 4
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Validar formulario

Muchas gracias por responder a mi pregunta, la verdad no pude validar el formulario mejor opte por otra opcion asi que aqui les dejo el codigo que me resulto mas facil validar de antemano muchisisismas gracias.
Código:
function validar()
{
  var alias=document.getElementById("alias").value;
  var at=document.getElementById("contrasena").value;
  var at2=document.getElementById("contrasena2").value;
  var nom=document.getElementById("nombre").value;
  var ap_pat=document.getElementById("ap_pat").value;
  var ap_mat=document.getElementById("ap_mat").value;
  var nac=document.getElementById("dateArrival").value;
  var correo=document.getElementById("email").value.indexOf("@");
  
  if (alias.length<=2) {
     alert("Es obligatorio indicar un Alias");
     cyberflog.alias.focus();
	 return false;
  }

  if (at.length <=3) {
     alert("contraseña debe de tener por lo menos 4 caracteres");
	 cyberflog.contrasena.focus();
     return false;
  }
  
  if(at!=at2){
     alert("Las contraseñas no coinciden");
	 cyberflog.contrasena2.value="";
	 cyberflog.contrasena2.focus();
     return false;
  }
  
  if (nom.length <=2) {
     alert("Es obligatorio indicar un Nombre");
     cyberflog.nombre.focus();
	 return false;
  }
	 
  if (ap_pat.length<=2) {
     alert("Es obligatorio indicar Apellido Paterno");
     cyberflog.ap_pat.focus();
	 return false;
 }
	 
  if (ap_mat.length<=2) {
     alert("Es obligatorio indicar Apellido Materno");
     cyberflog.ap_mat.focus();
	 return false;
 }
 
 if (nac.length==0) {
     alert("Ingresa tu Fecha de Nacimiento");
     cyberflog.fecha_nacimiento.focus();
	 return false;
 }
	 
  if (correo==-1) {
     alert("Dirección de correo electrónico no válida");
	 cyberflog.email.focus();
     return false;
  }
  
}
y el formulario

Código HTML:
<html>
<head>
<title>FORMULARIO</title>
<script language="javascript" src="popcalendar.js"></script>
<script language="javascript" src="validar.js"></script>
</head>
<body>
 
 
<form name="cyberflog"  action="altausuario.php" onSubmit="return validar()">
	  <p>&nbsp;</p>
	  <table width="368" border="5" align="center" bordercolordark="#000000" bgcolor="#999999">
	  <tr>
	  		<td>
  Alias: 
      </td>
	  		<td>
	  <input type="text" id="alias" s name="alias" />
	  		</td>
	  
	  </tr>
      <tr>
	  		<td>  
	  contraseña:
	  		</td>
	  		<td> 
	  <input  type="password" id="contrasena"  name="contrasena" />
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Repetir Contraseña:
	  		</td>
	  		<td> 
	  <input  type="password" id="contrasena2"  name="contrasena2"/> 
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Nombre:
	  		</td>
	  		<td> 
	  <input  type="text" id="nombre"  name="nombre"/>
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Apellido Paterno:
	  		</td>
	  		<td> 
	  <input  type="text" id="ap_pat"  name="ap_pat"/>
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Apellido Materno:
	  		</td>
	  		<td> 
	  <input  type="text" id="ap_mat"  name="ap_mat"/> 
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Sexo:
	  		</td>
	  		<td> 
	  <select name="sexo" id="sexo">
        <option selected="selected" >femenino</option>
        <option>masculino</option>
              </select> 
	  		</td>
	  </tr>
	  <tr>
	  		<td>  
	  Fecha de Nacimiento:
	  		</td>
	  		<td> 
	 <input name="fecha_nacimiento" type="text" id="dateArrival" onClick="popUpCalendar(this,cyberflog.dateArrival, 'yyyy-mm-dd');"  readonly="true"> 
	  		</td>
	  </tr>
	  <tr>
	  		<td>
		E-mail:
			</td>
			<td>
			<input type="text" id="email"  name="email" size="15"/>
			<select name="htl" id="htl">
				 <option selected="selected"> hotmail.com</option>
				 <option > yahoo.com</option>
				 <option > gmail.com</option>
			</select>
			</td>
		</tr>
  </table>
      <div align="center"><br />
        <input type="submit" value="ENVIAR"  />
        <input type="reset" name="Submit" value="LIMPIAR" />
      </div>
</form>
 
</body>
</html> 
BYE Y GRACIAS POR TODO