Ver Mensaje Individual
  #7 (permalink)  
Antiguo 21/07/2009, 06:00
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 18 años, 1 mes
Puntos: 126
Respuesta: al cambiar etiqueta html si valida el formulario

Hola

Tarde, pero he entendido cual es el problemas

Prueba así

Código javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="es">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>Formulario</title>
  6. <script type="text/javascript">
  7.  
  8. function eliminaEspacios(cadena) {
  9. return (cadena.replace(/(^\s*)|(\s*$)/g,""));
  10.    }
  11.  
  12.  
  13. function checkFields(c) {
  14.  
  15. missinginfo = "";
  16.  
  17.     // Primer paso: Obtener el rut que ingreso el usuario
  18.     var nameCompleto = c.nombre.value;
  19.     // Eliminamos los caracteres raros, espacios, puntos, guiones.
  20.     // Pasamos a minusculas, y separamos el rut y el digito verificador
  21.     nameCompleto = nameCompleto.replace(/[ \.-]/g, "");
  22.     nameCompleto = nameCompleto.toLowerCase();
  23.     var nombre = nameCompleto.substring(0, nameCompleto.length - 1)
  24.  
  25. alert ("Campo con espacios al principio ("+c.nombre.value+") y al final");
  26.  
  27. var nombre1=eliminaEspacios(nombre);
  28.  
  29. alert ("Campo sin espacios al principio ("+nombre1+") y al final");
  30.  
  31. var mesaje1=eliminaEspacios(c.mensaje.value);
  32.  
  33. var email1=eliminaEspacios(c.email.value);
  34.  
  35. if (nombre1=="") {
  36. missinginfo += "\n     - Campo Nombre";
  37.  
  38. }
  39.  
  40. if (mesaje1=="") {
  41. missinginfo += "\n     - Campo Mensaje";
  42.  
  43. }
  44.  
  45.  
  46.  
  47. if ((email1 == "") ||
  48. (c.email.value.indexOf('@') == -1) ||
  49. (c.email.value.indexOf('.') == -1)) {
  50.  
  51. missinginfo += "\n     - Campo E-mail";
  52.  
  53. }
  54.  
  55.  
  56.  
  57. if (missinginfo != "") {
  58. missinginfo ="Los siguentes campos del formulario \n no han sido completados o tienen errores: \n" +
  59. "" +
  60. missinginfo + "" +
  61. "\n ";
  62. alert(missinginfo);
  63. return false;
  64. }
  65. else return true;
  66. }
  67.  
  68. </script>
  69. </head>
  70. <body>
  71. <form id="form1" name="form1" method="post" action="enviar.php" onsubmit="return checkFields(this);">
  72. <p>
  73.   <select name="correo" id="correo"   style="width:100px" >
  74.     <option selected="selected" value="prensa" > Prensa </option>
  75.     <option  value="ventas"> Ventas </option>
  76.   </select>
  77. </p>
  78. <p> Nombre:<br />
  79.     <label>
  80.   <input name="nombre" type="text" id="nombre" />
  81.     </label>
  82.     <br />
  83.   Telefono:<br />
  84.   <input name="telefono" type="text" id="telefono" />
  85.   <br />
  86.   Email:<br />
  87.   <input name="email" type="text" id="email" />
  88.   <br />
  89.   Mensaje:<br />
  90.   <textarea name="mensaje" id="mensaje" rows="" cols=""></textarea>
  91.   <br />
  92.   <label>
  93.   <input type="submit" name="Submit" value="Enviar Formulario" />
  94.   </label>
  95. </p>
  96. </form>
  97. </body>
  98. </html>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />