Ver Mensaje Individual
  #16 (permalink)  
Antiguo 20/02/2012, 11:46
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

ok pues bueno te voy a poner todo mi código que tengo en la pagina:

Código HTML:
Ver original
  1. <?PHP  //primera Tabla
  2. if(isset($_POST["Guardar"]))
  3. {
  4.  
  5. $FOLIO = $_POST['FOLIO'] = trim($_POST['FOLIO']);
  6. $CVE_MED = $_POST['CVE_MED'] = trim($_POST['CVE_MED']);
  7. $NOMBRE = $_POST['NOMBRE'] = trim($_POST['NOMBRE']);
  8. if (empty($ID)){$ID='NULL';}
  9. $FOLIO_CER = $_POST['FOLIO_CER'] = trim($_POST['FOLIO_CER']);
  10.  
  11. // Paso 1: Recibimos el formulario:
  12. $FOLIO = $_POST['FOLIO'] = trim($_POST['FOLIO']);
  13. mysql_connect("localhost", "root", "*******");
  14. mysql_select_db("PRONTO");
  15.  
  16. mysql_query ("INSERT INTO
  17. prueba (FOLIO, CVE_MED, NOMBRE, ID, FOLIO_CER, FECHA)
  18. VALUES('$FOLIO', '$CVE_MED', '$NOMBRE', $ID, '$FOLIO_CER',  NOW())", mysql_connect(localhost , root , ********));
  19.  
  20. }
  21. ?>
  22. function validar(){
  23.    if(document.getElementById("folio").value==""){
  24.       alert("por favor inserte el folio.");
  25. * * * document.getElementById("folio").focus();
  26. * * * return false;
  27.    }
  28.    if(document.getElementById("cve_med").value==""){
  29.       alert("por favor inserte clave de medicion.");
  30. * * * document.getElementById("cve_med").focus();
  31. * * * return false;
  32.    }
  33.    if(document.getElementById("id").value==""){
  34.       alert("por favor inserte el numero de identificación.");
  35. * * * document.getElementById("id").focus();
  36. * * * return false;
  37.    }
  38.    if(document.getElementById("folio_cer").value==""){
  39.       alert("por favor inserte el folio de certificado.");
  40. * * * document.getElementById("folio_cer").focus();
  41. * * * return false;
  42.    }
  43.    document.getElementById("formulario").submit();
  44. }
  45. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  46. <html xmlns="http://www.w3.org/1999/xhtml">
  47. <script type="text/javascript">
  48. function mostrarTab(obj) {
  49.     rolling=obj.scrollTop;
  50.     if(typeof obj.selectionStart == 'number') {
  51.         // Resto de navegadores
  52.         var start = obj.selectionStart;
  53.         var end = obj.selectionEnd;
  54.         obj.value = obj.value.substring(0, start)+"\t";
  55.         obj.value+= obj.value.substring(start, obj.value.length);
  56.         obj.focus();
  57.         obj.selectionStart =  obj.selectionEnd= end + 2;
  58.     }
  59.     else if(document.selection) {
  60.         // Internet Explorer
  61.         obj.focus();
  62.         var range = document.selection.createRange();
  63.         if(range.parentElement() != obj) return false;
  64.         if (range.text != "") {
  65.             if(typeof range.text == 'string'){
  66.                 document.selection.createRange().text ="\t"+range.text;
  67.             }
  68.             else obj.value += "\t";
  69.         }
  70.         else
  71.             obj.value += "\t";
  72.     }
  73.     obj.scrollTop=rolling;
  74. }
  75. function tabulador(form,field)
  76. {
  77. var next=0, found=false
  78. var f=form
  79. //if(event.keyCode!=13) return;
  80. for(var i=0;i<f.length;i++) {
  81.     if(field.name==f.item(i).name){
  82.         next=i+1;
  83.         found=true
  84.         break;
  85.     }
  86. }
  87. //MODIFICACION A LA FUNCION &&  f.item(next).style.display!='none'
  88. while(found){
  89.     if( f.item(next).disabled==false &&  f.item(next).type!='hidden' &&  f.item(next).style.display!='none'){
  90.         f.item(next).focus();
  91.         break;
  92.     }
  93.     else{
  94.         if(next<f.length-1)
  95.             next=next+1;
  96.         else
  97.             break;
  98.     }
  99. }
  100. }
  101. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  102. <title>pruebas</title>
  103. </head>
  104. <body onkeypress="return pulsar(event)" onLoad="document.formulario.FOLIO.focus()">
  105. <form name="formulario" id="formulario" action="<?=$_SERVER['PHP_SELF']?>" method="post" >
  106. <table width="850" border="1" align="center">
  107.   <tr>
  108.     <td><div align="center">*Folio</div></td>
  109.     <td><div align="center">
  110.       <input type="text" id="FOLIO" name="FOLIO" size="8" maxlength="8" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  111.     </div></td>
  112.   </tr>
  113.   <tr>
  114.     <td><div align="center">*Clave Medicion</div></td>
  115.     <td><div align="center">
  116.       <input type="text" id="CVE_MED" name="CVE_MED" size="2" maxlength="2" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  117.     </div></td>
  118.   </tr>
  119.   <tr>
  120.     <td><div align="center">Nombre</div></td>
  121.     <td><div align="center">
  122.       <input type="text" id="NOMBRE" name="NOMBRE" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  123.     </div></td>
  124.   </tr>
  125.   <tr>
  126.     <td><div align="center">*ID</div></td>
  127.     <td><div align="center">
  128.       <input type="text" id="ID" name="ID" size="2" maxlength="2" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  129.     </div></td>
  130.   </tr>
  131.   <tr>
  132.     <td><div align="center">*Folio de Certificado</div></td>
  133.     <td><div align="center">
  134.       <input type="text" id="FOLIO_CER" name="FOLIO_CER" size="9" maxlength="9" onkeyup = "this.value=this.value.toUpperCase();if (this.value.length == this.getAttribute('maxlength')){tabulador(this.form,this)}"/>
  135.     </div></td>
  136.   </tr>
  137.   <tr>
  138.     <td colspan="2">
  139.       <div align="center">
  140.         <input type="button" name="Guardar" value="Guardar" onClick="validar()" />
  141.         </div></td>
  142.   </tr>
  143. <label><div align="center">los campos marcados con un * son obligatorios</div></label>
  144. </form>
  145. </body>
  146. </html>

como podrás ver todo lo hago en una sola pagina, al parecer el único conflicto que tengo con el código es, le cambio el tipo del botón lo tenia como submit y así si me guarda pero no me hace la validación con respecto a los campos ya mencionados, pero cuando le pongo al botón tipo Button me hace la validación pero no me guarda
espero que enconchemos el error

de antemano te mando las gracias y que tengas una buena tarde

saludos y suerte