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

y con respecto a la método focus() si me me queda pero tengo un problema con eso.

como tengo los campos juntos se traba la pagina me muestra la alerta del folio y de la clave de medición te pongo el código que tengo con el método focus()


Código Javascript:
Ver original
  1. <script>
  2. function validar1(){
  3. * *if(document.getElementById("folio").value==""){
  4. * * * alert("por favor inserte el folio.");
  5. * * * document.getElementById("folio").focus();//aqui se debe de regresar al campo vacio
  6. * * * return;
  7. * *}
  8. }
  9. </script>
  10. <script>
  11. function validar2(){
  12. * *if(document.getElementById("cve_med").value==""){
  13. * * * alert("por favor inserte clave de medicion.");
  14. * * * document.getElementById("cve_med").focus();//aqui se debe de regresar al campo vacio
  15. * * * return;
  16. * *}
  17. }
  18. </script>
  19. <script>
  20. function validar3(){
  21. * *if(document.getElementById("id").value==""){
  22. * * * alert("por favor inserte el numero de identificacion.");
  23. * * * document.getElementById("id").focus();//aqui se debe de regresar al campo vacio
  24. * * * return;
  25. * *}
  26. }
  27. </script>
  28. <script>
  29. function validar4(){
  30. * *if(document.getElementById("folio_cer").value==""){
  31. * * * alert("por favor inserte el folio de certificado.");
  32. * * * document.getElementById("folio_cer").focus();//aqui se debe de regresar al campo vacio
  33. * * * return;
  34. * *}
  35. }
  36. </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" onBlur="validar1()"/>
  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" onBlur="validar2()"/>
  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" onBlur="validar3()"/>
  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" onBlur="validar4()"/>
  37.     </div></td>
  38.   </tr>
  39.   <tr>
  40.     <td colspan="2">
  41.       <div align="center">
  42.         <input type="submit" name="Guardar" value="Guardar" />
  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>

Espero que me puedas ayudar de cualquier manera con este problema

te doy las gracias por el tiempo que te tomas para revisar el tema

suerte buen día