Ver Mensaje Individual
  #6 (permalink)  
Antiguo 10/12/2010, 17:08
Avatar de ALANCIN
ALANCIN
 
Fecha de Ingreso: septiembre-2010
Ubicación: mexico
Mensajes: 43
Antigüedad: 14 años
Puntos: 0
Respuesta: consultar a la base al mover el foco

mmmm sorry specifike arriba ke soy nuevo en sto....no tengo idea pero ahora ke me mencionas lo de combos dependientes stube viendo unos ejemplos...

pero sigo sin entender me parece ke es mas facil hacerlos kon un evento Onchange

tal vez me komplike pero trate de usar mi logika y logre hacer esto...spero me puedan korregir ok....
Código PHP:
Ver original
  1. <table width="500" height="100" border="1" align="center">
  2.   <tr>
  3.     <td>ID Articulo: </td>
  4.     <td><label><?
  5.     $conexion = mysql_connect("localhost","root","root");
  6.         mysql_select_db("db",$conexion);
  7.  
  8.         $consulta = mysql_query("SELECT * FROM articulos", $conexion);
  9.        
  10.    
  11. echo '<select name="id_articulo" id="id_articulo" onChange="llena_precio()">';
  12. echo '<option value="0">Seleccione </option>';
  13.  
  14. //genera option
  15.   while ($rows = mysql_fetch_array($consulta)){
  16. echo '<option value=' . $rows["id_articulo"] . '>' . $rows["id_articulo"] . '</option>';
  17.  
  18.   }
  19.  
  20. echo '</select>';
  21.  
  22. ?>
  23.     </label></td>
  24.     </tr>
  25.   <tr>
  26.     <td>Cantidad</td>
  27.     <td><label>
  28.       <input name="cantidad" type="text" id="cantidad"/>
  29.     </label></td>
  30.     </tr>
  31.   <tr>
  32.     <td>Precio</td>
  33.     <td><label>
  34. <script>
  35. function llena_precio(precio){
  36.  
  37. var articulo = document.getElementById("id_articulo").value
  38.  
  39.     <?
  40.     $conexion = mysql_connect("localhost","root","root");
  41.         mysql_select_db("db",$conexion);
  42.  
  43.         ?> var precio = <? $consulta = mysql_query("SELECT * FROM articulos WHERE id_articulo = ?>" . articulo . "<?", $conexion);
  44.        
  45.     ?>
  46.    
  47.     document.getElementById("precio").value = precio
  48.    
  49.     document.id_articulo.focus()
  50.    
  51. return precio
  52.  
  53. }
  54. </script>
  55.          
  56.     <input name="precio" type="text" id="precio" />
  57.     </label></td>
  58.     </tr>
  59.   <tr>
  60.     <td>&nbsp;</td>
  61.     <td><label>
  62.      
  63.         <input name="siguiente" type="submit" id="siguiente" value="Siguiente"/>
  64.        
  65.     </label></td>
  66.     </tr>
  67. </table>


cabe mencionar ke asi komo sta el codigo me pinta en mi text de precio un "undefined"