Ver Mensaje Individual
  #23 (permalink)  
Antiguo 30/04/2010, 12:14
easy
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: ayuda con validación poco convencional

Cita:
Iniciado por zerokilled Ver Mensaje
con onsubmit no te funciona porque estas pasando como argumento una referencia incorrecta. es decir, this.form.email.value. this hace referencia al formulario (<FORM>). ¿a que hace referencia this.form? a undefined porque esa propiedad solo existe en los elementos de controles de formulario: input, select, textarea, etcétera.

OK, Grcias lo corregi y aqui esta, funciona


Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  2. <title>Documento sin t&iacute;tulo</title>
  3. <script type="text/javascript">
  4. function validar(valor){
  5.     if(document.contact.campo.value.length==0){
  6.     document.getElementById('nombre').style.display="inline"
  7.     document.contact.campo.focus()
  8.     return false;
  9.     } else {
  10.     document.getElementById('nombre').style.display="none"
  11.     }
  12.     if(document.contact.campo2.value.length==0){
  13.     document.getElementById('apellido').style.display="inline"
  14.     document.contact.campo2.focus()
  15.     return false;
  16.     } else {
  17.     document.getElementById('apellido').style.display="none"
  18.     }
  19.     if(document.contact.email.value.length==0){
  20.     document.getElementById('email').style.display="inline"
  21.     document.contact.email.focus()
  22.     return false;
  23.     } else {
  24.     document.getElementById('email').style.display="none"
  25.     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
  26.     } else {
  27.     document.getElementById('email2').style.display="inline"
  28.     document.contact.email.focus()
  29.     return false;
  30.     }
  31.     }
  32. }
  33. </head>
  34.  
  35. <form name="contact" action="index.php" method="post" onsubmit="return validar(email.value);">
  36. nombre: <input type="text" name="campo"  /> <b id="nombre" style="display:none; color:#ff0000;">Ingrese Nombre</b>
  37. <br /><br />
  38. apellido: <input type="text" name="campo2"  /> <b id="apellido" style="display:none; color:#ff0000;">Ingrese Apellido</b>
  39. <br /><br />
  40. email: <input type="text" name="email"  /> <b id="email" style="display:none; color:#ff0000;">Ingrese Email</b><b id="email2" style="display:none; color:#ff0000;">Email en formato no valido</b>
  41. <input type="submit" value="submit" />
  42. </form>
  43. </body>


Gracias nuevamente
__________________
$ayudar = 'ayudar es compartir';
echo $ayudar;