Tema: Combobox
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/04/2014, 11:33
jorgemedina2406
 
Fecha de Ingreso: abril-2014
Mensajes: 14
Antigüedad: 10 años
Puntos: 0
Exclamación Combobox

Necesito una ayudita con estos combos generados dinamicamente amigos.

Me funciona perfectamente, solo quiero que en el combo 2 y 3 sean iguales y aparezcan de acuerdo a lo seleccionado en el primero.

Mi codigo es el siguiente:

Archivo Principal.

Código PHP:
Ver original
  1. <?php
  2.   include "Conexion.php";
  3. ?>
  4.  
  5. <html>
  6. <head><title>SISTEMA DE INVENTARIO</title>
  7. <script type="text/javascript" language="javascript" src="funciones.js"></script>
  8.  
  9. </head>
  10. <body onLoad="limpiar()">
  11.  
  12. <center>
  13. <h1><font color="green">Recepcion de Equipo</font></h1>
  14. <hr />
  15. <form name="f_agregaequipo" method='post' action="agregaequipo.php">
  16.  
  17. <table border="10">
  18. <tr>
  19.  
  20. </tr><tr>
  21. <td>Fabricante:</td>
  22. <td>
  23. <div id="fabricante">
  24.    <select name="fabricante" onChange="from(document.f_agregaequipo.fabricante.value,'producto','combproducto.php')">
  25.        <option selected  disabled> </option>
  26.  
  27. <?php
  28.        
  29.           $sql="select * from t_fabricante order by fabricante asc";
  30.           $res=mysql_query($sql,$con);
  31.          
  32.           while ($reg=mysql_fetch_array($res))
  33.  
  34.    
  35.  
  36.   {
  37.  
  38.    
  39.  
  40.   ?>
  41.              <option value="<?php echo $reg["cod_fabricante"];?>"><?php echo $reg["fabricante"];?></option>
  42.           <?php
  43.  
  44.    
  45.  
  46.   }
  47.         ?>
  48.      </select>
  49. </div>  
  50. </td>
  51. </tr><tr>
  52.  
  53. <td>Producto:</td>
  54.   <td>
  55.    <div id="producto">
  56.      <select name="producto">
  57.        <option selected  disabled> </option>
  58.      </select>
  59.    </div>
  60.   </td>
  61. </tr><tr>  
  62.  
  63. <td>Modelo:</td>
  64.   <td>
  65.    <div id="modelo">
  66.      <select name="modelo">
  67.        <option selected  disabled> </option>
  68.      </select>  
  69.    </div>
  70.   </td>
  71. </tr><tr>    
  72.  
  73.  <td>Serial:</td>
  74.    <td>
  75.      <input type="text" name="serial" size="30" maxlength="30" />
  76.    </td>
  77.  </tr><tr>
  78.  
  79. <td>Ubication:</td>
  80.    <td>
  81.      <input type="text" name="ubicacion" size="30" maxlength="30" />
  82.    </td>
  83.  </tr><tr>
  84.  
  85. <td>Rack:</td>
  86.    <td>
  87.      <input type="text" name="rack" size="30" maxlength="30" />
  88.    </td>
  89.  </tr><tr>
  90.  
  91. <td>Bin:</td>
  92.    <td>
  93.      <input type="text" name="bin" size="30" maxlength="30" />
  94.    </td>
  95.  </tr><tr>
  96.  
  97. <td>Date:</td>
  98.    <td>
  99.      <input Disabled name="fecha" value="<?php echo date("m/d/Y H:i:s"); ?>" size="15" />
  100.      
  101.    </td>
  102.  </tr><tr>
  103.  
  104.    <td><input type="submit" value="Enviar"/></td>
  105.    <td><input type ="reset" value = "reetablecer"> </td>
  106.  
  107. </tr>
  108. </table>
  109.  
  110. </form>
  111. </center>
  112. <br /><hr />
  113. </body>
  114. </html>

Archivo comboproducto.php

Código PHP:
<?php
include "Conexion.php";

$sql="select * from t_producto where cod_fabricante=".$_GET["id"]."";

$res=mysql_query($sql,$con); 

?>
<select name="producto" onchange="from(document.f_agregaequipo.producto.value,'modelo','combmodelo.php')"> 
    <option selected  disabled> </option>
    
    <?php

while ($reg=mysql_fetch_array($res))

    

{

    

?>
    
    <option value="<?php echo $reg["cod_producto"];?>"><?php echo $reg["producto"];?></option>
    
    
    
    
    <?php

    

}
   
?>
  </select>
Archivo agregaequipo.php

Código PHP:
<?php 
  
// Se establece la conexión con la fuente de datos
  
$con mysql_connect("localhost""root""123");
  
// Si no hay conexión, se emite un error y se aborta
  
if (!$con)   
     die (
"Error en la conexión con el gestor");
  
mysql_select_db("inventario") or die("Error en la Base de Datos");

// Utilizamos el codigo del Fabricante tomado del select y los utilizamos para buscar el nombre del fabricante.
  
$cod_fabricante $_POST["fabricante"];
  
$sql "SELECT fabricante FROM t_fabricante WHERE cod_fabricante = $cod_fabricante";
  
$res1 =  mysql_query($sql,$con);
  while (
$reg=mysql_fetch_array($res1)){  
     
$fabricante $reg["fabricante"];
  }

// Utilizamos el codigo del Producto tomado del select y los utilizamos para buscar el nombre del Producto.
  
$cod_producto $_POST["producto"];
  
$sql "SELECT producto FROM t_producto WHERE cod_producto = $cod_producto";
  
$res2 =  mysql_query($sql,$con);
  while (
$reg=mysql_fetch_array($res2)){  
     
$producto $reg["producto"];
  } 

// Utilizamos el codigo del Modelo tomado del select y los utilizamos para buscar el nombre del Modelo.
  
$cod_modelo $_POST["modelo"];
  
$sql "SELECT modelo FROM t_modelo WHERE cod_modelo = $cod_modelo";
  
$res3 =  mysql_query($sql,$con);
  while (
$reg=mysql_fetch_array($res3)){  
     
$modelo $reg["modelo"];
  } 

  
$insertar ="INSERT INTO t_agregaequipo VALUES ('$fabricante','$producto','$modelo','$_POST[serial]','$_POST[ubicacion]','$_POST[rack]','$_POST[bin]','$_POST[fecha]')";
  

      
  
// Se solicita la ejecución de la nueva instrucción (Insert) 
  
$resultado mysql_query($insertar);
  
  
// Se cierra la conexión
  
mysql_close();
  require(
'f_agregaequipo.php');
?>
Archivo combomodelo.php

Código PHP:
<?php

    

include "Conexion.php";

    

$sql="select * from t_modelo where cod_producto=".$_GET["id"]."";

    

$res=mysql_query($sql,$con); 
?>
<select name="modelo"> 
  <option selected  disabled> </option>
   <?php

    

while ($reg=mysql_fetch_array($res))

    

{

    

?>

    

<option value="<?php echo $reg["cod_modelo"];?>"><?php echo $reg["modelo"];?></option>

    

<?php

    

}
   
?>
</select>
Archivo funciones.js

Código Javascript:
Ver original
  1. function obtiene_http_request()
  2. {
  3. var req = false;
  4. try
  5.   {
  6.     req = new XMLHttpRequest(); /* p.e. Firefox */
  7.   }
  8. catch(err1)
  9.   {
  10.   try
  11.     {
  12.      req = new ActiveXObject("Msxml2.XMLHTTP");
  13.   /* algunas versiones IE */
  14.     }
  15.   catch(err2)
  16.     {
  17.     try
  18.       {
  19.        req = new ActiveXObject("Microsoft.XMLHTTP");
  20.   /* algunas versiones IE */
  21.       }
  22.       catch(err3)
  23.         {
  24.          req = false;
  25.         }
  26.     }
  27.   }
  28. return req;
  29. }
  30. var miPeticion = obtiene_http_request();
  31. //***************************************************************************************
  32. function from(id,ide,url){
  33.       var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
  34.       var vinculo=url+"?id="+id+"&rand="+mi_aleatorio;
  35.       //alert(vinculo);
  36.       miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
  37.       miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
  38.                if (miPeticion.readyState==4)
  39.                {
  40.                //alert(miPeticion.readyState);
  41.                        if (miPeticion.status==200)
  42.                        {
  43.                                 //alert(miPeticion.status);
  44.                                //var http=miPeticion.responseXML;
  45.                                var http=miPeticion.responseText;
  46.                                document.getElementById(ide).innerHTML= http;
  47.  
  48.                        }
  49.                }/*else
  50.                {
  51.          document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />";
  52.  
  53.                 }*/
  54.        }
  55.        miPeticion.send(null);
  56.  
  57. }
  58. //************************************************************************************************
  59. function limpiar()
  60. {
  61.    document.form.reset();
  62.    
  63. }

Espero me puedan ayudar a colocar los combos: producto y modelos iguales, que se desplieguen los 2 depende de lo que seleccione en el 1ero.