Ver Mensaje Individual
  #11 (permalink)  
Antiguo 15/02/2012, 12:03
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

buenos dias lukas4
ok pues si lo hago con el botón queda así todo mi código


Código Javascript:
Ver original
  1. <script>
  2. function validar(){
  3.    if(document.getElementById("folio").value==""){
  4.       alert("por favor inserte el folio.");
  5.    }
  6.    if(document.getElementById("cve_med").value==""){
  7.       alert("por favor inserte clave de medicion.");
  8.    }
  9.    if(document.getElementById("id").value==""){
  10.       alert("por favor inserte el numero de identificación.");
  11.    }
  12.    if(document.getElementById("folio_cer").value==""){
  13.       alert("por favor inserte el folio de certificado.");
  14.    }
  15. }
  16. </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"/>
  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" name="cve_med"/>
  19.     </div></td>
  20.   </tr>
  21.   <tr>
  22.     <td><div align="center">Nombre</div></td>
  23.     <td><div align="center">
  24.       <input type="text" 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"/>
  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"/>
  37.     </div></td>
  38.   </tr>
  39.   <tr>
  40.     <td colspan="2">
  41.       <div align="center">
  42.         <input type="submit" name="Guardar" value="Guardar" onclick="validar()" />
  43.         </div></td>
  44.   </tr>
  45. <labe>
  46. <div align="center">los campos marcados con un * son obligatorios
  47.   </label>
  48. </div>
  49. </form>
  50. </body>
  51. </html>
No se en donde esta el error por que cuando le doy en el botón de guardar me borra la información

De antemano te doy las gracias y buen día