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
<?php include "Conexion.php"; ?> <html> <head><title>SISTEMA DE INVENTARIO</title> <script type="text/javascript" language="javascript" src="funciones.js"></script> </head> <body onLoad="limpiar()"> <center> <h1><font color="green">Recepcion de Equipo</font></h1> <hr /> <form name="f_agregaequipo" method='post' action="agregaequipo.php"> <table border="10"> <tr> </tr><tr> <td>Fabricante:</td> <td> <div id="fabricante"> <select name="fabricante" onChange="from(document.f_agregaequipo.fabricante.value,'producto','combproducto.php')"> <option selected disabled> </option> <?php $sql="select * from t_fabricante order by fabricante asc"; { ?> <option value="<?php echo $reg["cod_fabricante"];?>"><?php echo $reg["fabricante"];?></option> <?php } ?> </select> </div> </td> </tr><tr> <td>Producto:</td> <td> <div id="producto"> <select name="producto"> <option selected disabled> </option> </select> </div> </td> </tr><tr> <td>Modelo:</td> <td> <div id="modelo"> <select name="modelo"> <option selected disabled> </option> </select> </div> </td> </tr><tr> <td>Serial:</td> <td> <input type="text" name="serial" size="30" maxlength="30" /> </td> </tr><tr> <td>Ubication:</td> <td> <input type="text" name="ubicacion" size="30" maxlength="30" /> </td> </tr><tr> <td>Rack:</td> <td> <input type="text" name="rack" size="30" maxlength="30" /> </td> </tr><tr> <td>Bin:</td> <td> <input type="text" name="bin" size="30" maxlength="30" /> </td> </tr><tr> <td>Date:</td> <td> </td> </tr><tr> <td><input type="submit" value="Enviar"/></td> <td><input type ="reset" value = "reetablecer"> </td> </tr> </table> </form> </center> <br /><hr /> </body> </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>
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');
?>
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>
Código Javascript:
Ver original
function obtiene_http_request() { var req = false; try { req = new XMLHttpRequest(); /* p.e. Firefox */ } catch(err1) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); /* algunas versiones IE */ } catch(err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */ } catch(err3) { req = false; } } } return req; } var miPeticion = obtiene_http_request(); //*************************************************************************************** function from(id,ide,url){ var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché... var vinculo=url+"?id="+id+"&rand="+mi_aleatorio; //alert(vinculo); miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){ if (miPeticion.readyState==4) { //alert(miPeticion.readyState); if (miPeticion.status==200) { //alert(miPeticion.status); //var http=miPeticion.responseXML; var http=miPeticion.responseText; document.getElementById(ide).innerHTML= http; } }/*else { document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />"; }*/ } miPeticion.send(null); } //************************************************************************************************ function limpiar() { document.form.reset(); }
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.