Ir al contenido


Foto

Combos Anidados Ayudaaa


  • Por favor identifícate para responder
2 respuestas en este tema

#1 snowdogs

snowdogs

    Newbie

  • Miembros
  • Pip
  • 2 mensajes

Escrito 21 abril 2014 - 06:27

Buenas tardes, espero me puedan ayudar, tengo el siguiente codigo para realizar unos combos anidados y luego guardarlos a la base de dato, el problema es que solo me muestra los datos del primer combo, los demas me los deberia mostrar depende de lo que seleccione en el primero, y el 3ro depende de lo que seleccione en el 2do.

El codigo que tengo es el siguiente:

Archivo f_agregaequipo.php



php
  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.    
  28.  
  29. <?php
  30.        
  31.           $sql="select * from t_fabricante order by fabricante asc";
  32.           $res=mysql_query($sql,$con);
  33.          
  34.           while ($reg=mysql_fetch_array($res))
  35.  
  36.    
  37.  
  38.   {
  39.  
  40.    
  41.  
  42.   ?>
  43.             <option value="<?php echo $reg["cod_fabricante"];?>"><?php echo $reg["fabricante"];?></option>
  44.           <?php
  45.  
  46.    
  47.  
  48.   }
  49.         ?>
  50.     </select>
  51. </div> 
  52. </td>
  53. </tr><tr>
  54.  
  55. <td>Producto:</td>
  56.   <td>
  57.   <div id="producto">
  58.     <select name="producto">
  59.       <option selected  disabled> </option>
  60.     </select> 
  61.   </div>
  62.   </td>
  63. </tr><tr> 
  64.  
  65. <td>Modelo:</td>
  66.   <td>
  67.   <div id="modelo">
  68.     <select name="modelo">
  69.       <option selected  disabled> </option>
  70.     </select> 
  71.   </div>
  72.   </td>
  73. </tr><tr>   
  74.  
  75. <td>Serial:</td>
  76.   <td>
  77.     <input type="text" name="serial" size="30" maxlength="30" />
  78.   </td>
  79. </tr><tr>
  80.  
  81. <td>Ubication:</td>
  82.   <td>
  83.     <input type="text" name="ubicacion" size="30" maxlength="30" />
  84.   </td>
  85. </tr><tr>
  86.  
  87. <td>Rack:</td>
  88.   <td>
  89.     <input type="text" name="rack" size="30" maxlength="30" />
  90.   </td>
  91. </tr><tr>
  92.  
  93. <td>Bin:</td>
  94.   <td>
  95.     <input type="text" name="bin" size="30" maxlength="30" />
  96.   </td>
  97. </tr><tr>
  98.  
  99. <td>Date:</td>
  100.   <td>
  101.     <input Disabled name="fecha" value="<?php echo date("m/d/Y H:i:s"); ?>" size="15" />
  102.    
  103.   </td>
  104. </tr><tr>
  105.  
  106.   <td><input type="submit" value="Enviar"/></td>
  107.   <td><input type ="reset" value = "reetablecer"> </td>
  108.  
  109. </tr>
  110. </table>
  111.  
  112. </form>
  113. </center>
  114. <br /><hr />
  115. </body>
  116. </html>



Archivo combproducto.php



php
  1. <?php
  2.  
  3.    
  4.  
  5. include "Conexion.php";
  6.  
  7.    
  8.  
  9. $sql="select * from t_producto where cod_fabricante=".$_POST["id"]."";
  10.  
  11.    
  12.  
  13. $res=mysql_query($sql,$con);
  14. ?>
  15. <select name="producto" onchange="from(document.f_agregaequipo.producto.value,'modelo','combmodelo.php')">
  16.   <option selected  disabled> </option>
  17.   <?php
  18.  
  19.    
  20.  
  21. while ($reg=mysql_fetch_array($res))
  22.  
  23.    
  24.  
  25. {
  26.  
  27.    
  28.  
  29. ?>
  30.  
  31.    
  32.  
  33. <option value="<?php echo $reg["cod_producto"];?>"><?php echo $reg["producto"];?></option>
  34.  
  35.    
  36.  
  37. <?php
  38.  
  39.    
  40.  
  41. }
  42.   ?>
  43. </select>



Archivo combmodelo.php



php
  1. <?php
  2.  
  3.    
  4.  
  5. include "Conexion.php";
  6.  
  7.    
  8.  
  9. $sql="select * from t_modelo where cod_producto=".$_POST["id"]."";
  10.  
  11.    
  12.  
  13. $res=mysql_query($sql,$con);
  14. ?>
  15. <select name="modelo">
  16.   <option selected  disabled> </option>
  17.   <?php
  18.  
  19.    
  20.  
  21. while ($reg=mysql_fetch_array($res))
  22.  
  23.    
  24.  
  25. {
  26.  
  27.    
  28.  
  29. ?>
  30.  
  31.    
  32.  
  33. <option value="<?php echo $reg["cod_modelo"];?>"><?php echo $reg["modelo"];?></option>
  34.  
  35.    
  36.  
  37. <?php
  38.  
  39.    
  40.  
  41. }
  42.   ?>
  43. </select>
  44. [/Code
  45. ]
  46. [color=green][b]Archivo agregaequipo.php[/b][/color]
  47.  
  48. [code=PHP]
  49. <?php
  50.   // Se establece la conexión con la fuente de datos
  51.   $con = mysql_connect("localhost", "root", "123");
  52.   // Si no hay conexión, se emite un error y se aborta
  53.   if (!$con) 
  54.     die ("Error en la conexión con el gestor");
  55.   mysql_select_db("inventario") or die("Error en la Base de Datos");
  56.  
  57. // Utilizamos el codigo del Fabricante tomado del select y los utilizamos para buscar el nombre del fabricante.
  58.   $cod_fabricante = $_POST["fabricante"];
  59.   $sql = "SELECT fabricante FROM t_fabricante WHERE cod_fabricante = $cod_fabricante";
  60.   $res1 =  mysql_query($sql,$con);
  61.   while ($reg=mysql_fetch_array($res1)){ 
  62.     $fabricante = $reg["fabricante"];
  63.   }
  64.  
  65. // Utilizamos el codigo del Producto tomado del select y los utilizamos para buscar el nombre del Producto.
  66.   $cod_producto = $_POST["producto"];
  67.   $sql = "SELECT producto FROM t_producto WHERE cod_producto = $cod_producto";
  68.   $res2 =  mysql_query($sql,$con);
  69.   while ($reg=mysql_fetch_array($res2)){ 
  70.     $producto = $reg["producto"];
  71.   }
  72.  
  73. // Utilizamos el codigo del Modelo tomado del select y los utilizamos para buscar el nombre del Modelo.
  74.   $cod_modelo = $_POST["modelo"];
  75.   $sql = "SELECT modelo FROM t_modelo WHERE cod_modelo = $cod_modelo";
  76.   $res3 =  mysql_query($sql,$con);
  77.   while ($reg=mysql_fetch_array($res3)){ 
  78.     $modelo = $reg["modelo"];
  79.   }
  80.  
  81.   $insertar ="INSERT INTO t_agregaequipo VALUES ('$fabricante','$producto','$modelo','$_POST[serial]','$_POST[ubicacion]','$_POST[rack]','$_POST[bin]','$_POST[fecha]')";
  82.  
  83.  
  84.      
  85.   // Se solicita la ejecución de la nueva instrucción (Insert)
  86.   $resultado = mysql_query($insertar);
  87.  
  88.   // Se cierra la conexión
  89.   require('f_agregaequipo.php');
  90. ?>
  91. [/code]
  92.  
  93. [color=green][b]Y por ultimo el archivo funciones.js que me esta dando un error en la linea 34 donde esta: var vinculo=url
  94.  
  95. El codigo es el siguiente:[/b][/color]
  96.  
  97. [code=Java]
  98.     function obtiene_http_request()
  99.     {
  100.     var req = false;
  101.     try
  102.       {
  103.         req = new XMLHttpRequest(); /* p.e. Firefox */
  104.       }
  105.     catch(err1)
  106.       {
  107.       try
  108.         {
  109.         req = new ActiveXObject("Msxml2.XMLHTTP");
  110.       /* algunas versiones IE */
  111.         }
  112.       catch(err2)
  113.         {
  114.         try
  115.           {
  116.           req = new ActiveXObject("Microsoft.XMLHTTP");
  117.       /* algunas versiones IE */
  118.           }
  119.           catch(err3)
  120.             {
  121.             req = false;
  122.             }
  123.         }
  124.       }
  125.     return req;
  126.     }
  127.     var miPeticion = obtiene_http_request();
  128.     //***************************************************************************************
  129.     function from(id,ide,url){
  130.           var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
  131.           var vinculo=url "?id=" id "&rand=" mi_aleatorio;
  132.           //alert(vinculo);
  133.           miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
  134.           miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
  135.                   if (miPeticion.readyState==4)
  136.                   {
  137.                   //alert(miPeticion.readyState);
  138.                           if (miPeticion.status==200)
  139.                           {
  140.                                     //alert(miPeticion.status);
  141.                                   //var http=miPeticion.responseXML;
  142.                                   var http=miPeticion.responseText;
  143.                                   document.getElementById(ide).innerHTML= http;
  144.    
  145.                           }
  146.                   }/*else
  147.                   {
  148.             document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />";
  149.    
  150.                     }*/
  151.           }
  152.           miPeticion.send(null);
  153.    
  154.     }
  155.     //************************************************************************************************
  156.     function limpiar()
  157.     {
  158.       document.form.reset();
  159.      
  160.     }


  • 0

#2 Sephiroth_801

Sephiroth_801

    Member

  • Miembros
  • PipPip
  • 26 mensajes

Escrito 25 abril 2014 - 08:38

La línea que tú mencionas al final: var vinculo=url "?id=" id "&rand=" mi_aleatorio;, no faltarían los "+", para concatenar.
Quedando:

delphi
  1. var vinculo=url+"?id="+id+"&rand="+mi_aleatorio;



Solo me fije en eso, no he revisado el resto del código. xD
  • 0

#3 snowdogs

snowdogs

    Newbie

  • Miembros
  • Pip
  • 2 mensajes

Escrito 25 abril 2014 - 08:59

Excelente amigo Sephiroth_801 si me sirvio, ahora otra preguntica si no es mucha molestia, como hago para que el primer combo me active los otros 2 de una vez, y que los otros 2 sean los mismos.
  • 0




IP.Board spam blocked by CleanTalk.