Ver Mensaje Individual
  #14 (permalink)  
Antiguo 16/02/2012, 16:21
Avatar de mexbale
mexbale
 
Fecha de Ingreso: septiembre-2010
Ubicación: Iztapalapa
Mensajes: 146
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: validar antes de guardar

Estimado lukas4 la primera opción que me poner si me funciona me manda el alerta cuando no lleno los campo y no me borra la información, pero cuando ya lleno todos los campos y le doy guardar no me guarda nada en mi base de datos el código quedo así:


Código Javascript:
Ver original
  1. <script>
  2. function validar(){
  3.    if(document.getElementById("folio").value==""){
  4.       alert("por favor inserte el folio.");
  5. * * * document.getElementById("folio").focus();
  6. * * * return false;
  7.    }
  8.    if(document.getElementById("cve_med").value==""){
  9.       alert("por favor inserte clave de medicion.");
  10. * * * document.getElementById("cve_med").focus();
  11. * * * return false;
  12.    }
  13.    if(document.getElementById("id").value==""){
  14.       alert("por favor inserte el numero de identificación.");
  15. * * * document.getElementById("id").focus();
  16. * * * return false;
  17.    }
  18.    if(document.getElementById("folio_cer").value==""){
  19.       alert("por favor inserte el folio de certificado.");
  20. * * * document.getElementById("folio_cer").focus();
  21. * * * return false;
  22.    }
  23.    document.getElementById("formulario").submit();
  24. }
  25. </script>
Código HTML:
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">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>pruebas</title>
  5. </head>
  6. <body onkeypress="return pulsar(event)" onLoad="document.formulario.FOLIO.focus()">
  7. <form name="formulario" id="formulario" action="<?=$_SERVER['PHP_SELF']?>" method="post" >
  8. <table width="850" border="1" align="center">
  9.   <tr>
  10.     <td><div align="center">*Folio</div></td>
  11.     <td><div align="center">
  12.       <input type="text" id="FOLIO" name="FOLIO" size="8" maxlength="8"/>
  13.     </div></td>
  14.   </tr>
  15.   <tr>
  16.     <td><div align="center">*Clave Medicion</div></td>
  17.     <td><div align="center">
  18.       <input type="text" id="CVE_MED" name="CVE_MED" size="2" maxlength="2"/>
  19.     </div></td>
  20.   </tr>
  21.   <tr>
  22.     <td><div align="center">Nombre</div></td>
  23.     <td><div align="center">
  24.       <input type="text" id="NOMBRE" name="NOMBRE"/>
  25.     </div></td>
  26.   </tr>
  27.   <tr>
  28.     <td><div align="center">*ID</div></td>
  29.     <td><div align="center">
  30.       <input type="text" id="ID" name="ID" size="2" maxlength="2"/>
  31.     </div></td>
  32.   </tr>
  33.   <tr>
  34.     <td><div align="center">*Folio de Certificado</div></td>
  35.     <td><div align="center">
  36.       <input type="text" id="FOLIO_CER" name="FOLIO_CER" size="9" maxlength="9"/>
  37.     </div></td>
  38.   </tr>
  39.   <tr>
  40.     <td colspan="2">
  41.       <div align="center">
  42.         <input type="button" name="Guardar" value="Guardar" onClick="validar()" />
  43.         </div></td>
  44.   </tr>
  45. <label><div align="center">los campos marcados con un * son obligatorios</div></label>
  46. </form>
  47. </body>
  48. </html>

no se en que estoy mal y por que no me guarda

no se si podrías checarlo y decirme en que estoy mal o cual es mi error

de antemano te doy las gracias