Ver Mensaje Individual
  #5 (permalink)  
Antiguo 17/12/2009, 10:02
mmejias
 
Fecha de Ingreso: julio-2009
Mensajes: 13
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Duda con validacion

Bueno te voy a mostrar el codigo que tengo de javascript...

Tengo 2 paginas en php, la primera contiene un formulario y tiene el siguiente codigo en javascript

a:
Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <title>Documento sin t&iacute;tulo</title>
  4. <script type="text/javascript" src="ajax.js"></script>
  5. <script type="text/javascript">
  6.    
  7.     var ajax = new sack();
  8.     var currentClientID=false;
  9.     var currentClientID2=false;
  10.     function getClientData()
  11.     {
  12.         var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
  13.         var clientId2 = document.getElementById('clientID2').value.replace(/[^0-9]/g,'');
  14.         if((clientId!=currentClientID) && (clientId2!=currentClientID2)){
  15.             currentClientID = clientId;
  16.             currentClientID2 = clientId2;
  17.             ajax.requestFile = 'b.php?getClientId='+clientId+'&getClientId2='+clientId2;    // Specifying which file to get
  18.             ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found
  19.             ajax.runAJAX();     // Execute AJAX function           
  20.         }
  21.        
  22.     }
  23.    
  24.     function showClientData()
  25.     {
  26.         var formObj = document.forms['clientForm'];
  27.         eval(ajax.response);
  28.     }
  29.    
  30.    
  31.     function initFormEvents()
  32.     {
  33.         document.getElementById('clientID').onblur = getClientData;
  34.         document.getElementById('clientID2').onblur = getClientData;
  35.         document.getElementById('clientID').focus();
  36.     }
  37.    
  38.    
  39.     window.onload = initFormEvents;
  40. </head>
  41.  
  42. <form name="clientForm" method="POST" action="">
  43. <table width="522" border="0" cellpadding="0" cellspacing="0">
  44.   <!--DWLayoutTable-->
  45.   <tr>
  46.     <td width="522" height="72">&nbsp;</td>
  47.   </tr>
  48.   <tr>
  49.     <td height="20" valign="top">Partida:
  50.       <label>
  51.       <input type="text" tabindex="1" name="clientID" id="clientID">
  52.     </label></td>
  53.   </tr>
  54.   <tr>
  55.     <td height="20" valign="top">Formulario:
  56.       <label>
  57.       <input type="text" name="clientID2" id="clientID2" tabindex="2">
  58.     </label></td>
  59.   </tr>
  60.   <tr>
  61.     <td height="20" valign="top">Partida Anterior:
  62.       <label>
  63.       <input type="text" name="textfield3" id="textfield3" readonly>
  64.     </label></td>
  65.   </tr>
  66.   <tr>
  67.     <td height="20" valign="top">Precio Unitario:
  68.       <label>
  69.       <input type="text" name="textfield4" id="textfield4" readonly>
  70.     </label></td>
  71.   </tr>
  72.   <tr>
  73.     <td height="20" valign="top">Precio Actual:
  74.       <label>
  75.       <input type="text" name="textfield5" id="textfield5" readonly>
  76.     </label></td>
  77.   </tr>
  78.   <tr>
  79.     <td height="20" valign="top">Obra:
  80.       <label>
  81.       <input type="text" name="textfield6" id="textfield6" tabindex="3" readonly>
  82.     </label></td>
  83.   </tr>
  84.   <tr>
  85.     <td height="33">&nbsp;</td>
  86.   </tr>
  87.   <tr>
  88.   </tr>
  89.   <tr>
  90.     <td height="95">&nbsp;</td>
  91.   </tr>
  92. </form>
  93. </body>
  94. </html>


Dentro del Formulario contiene unas 5 cajas de texto, de las cuales 2 son los datos que yo ingreso y lo que hace este script es que despues que cambie de caja de texto el me muestra una consulta en las siguientes 3 cajas de texto. La consulta la toma de la siguiente página y el codigo es el siguiente:

b:
Código PHP:
Ver original
  1. <?php
  2. if (!isset($_SESSION)) {
  3. }
  4. $_SESSION['part']=$_GET['getClientId'];
  5. $_SESSION['part2']=$_GET['getClientId2'];
  6. $connection = mysql_connect("localhost","userlector","123456");  
  7. mysql_select_db("partidas",$connection);
  8.  
  9. if(isset($_GET['getClientId'])){  
  10.   $res = mysql_query("select * from partidasval where formularioriginal=".$_GET['getClientId']." and nropartoriginal=".$_GET['getClientId2']."") or die(mysql_error());
  11.   if($inf = mysql_fetch_array($res)){
  12.     echo "formObj.textfield4.value = '".$inf["descripcion"]."';\n";    
  13.     echo "formObj.textfield5.value = '".$inf["unidad"]."';\n";    
  14.     echo "formObj.textfield3.value = '".$inf["nropartidatransbarca"]."';\n";    
  15.     echo "formObj.textfield6.value = '".$inf["pu_act_escalatoria"]."';\n";    
  16.    
  17.   }else{
  18.     echo "formObj.textfield3.value = '';\n";    
  19.     echo "formObj.textfield4.value = '';\n";    
  20.     echo "formObj.textfield5.value = '';\n";    
  21.     echo "formObj.textfield6.value = '';\n";    
  22.   }    
  23. }
  24. ?>

La primera caja de texto que se llama clientID es la que necesito que admita valores float ya que solo me funciona la consulta con valores enteros.

Si no se entiende todavia me avisan para tratar de ver una mejor forma de explicarlo