Ver Mensaje Individual
  #3 (permalink)  
Antiguo 23/01/2014, 08:12
charly_lpg
 
Fecha de Ingreso: octubre-2013
Mensajes: 56
Antigüedad: 10 años, 6 meses
Puntos: 1
Respuesta: Problema con select anidados

Hola
te paso el codigo de HTML. estan en un solo archivo los Scripts

Código PHP:
<?php
require_once("funciones.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formulario con SELECT > OPTION Dinamico</title>
<script src="jquery-1.10.2.min.js"></script>
</head>

<body>
<form style="width: 480px">
    <fieldset>
    <legend>Seleccione su entidad federativa</legend>
    <label>Linea Aerea:</label>
        <select name="cia" id="cia">
                <option value="">Seleccione una Linea Aerea</option>
        <?php
        $cia 
dameCia();
        
        foreach(
$cia as $indice => $registro){
            echo 
"<option value=".$registro['cia'].">".$registro['aerolinea']."</option>";
        }
        
?>
    </select>
    <br><br>
    <label>Tarjeta:</label>
        <select name="tc" id="tc">
                <option value="">Primero seleccione una Linea Aerea</option>
    </select>
    <br><br>
    <label>Banco:</label>
        <select name="bco" id="bco">
                <option value="">Primero seleccione una Tarjeta</option>
    </select>
    <br><br>
    <label>Cuotas:</label>
        <select name="cta" id="cta">
                <option value="">Primero seleccione un Banco</option>
    </select>
    </fieldset>
</form>
<hr>
<script>
$("#cia").on("change", buscarTc);
$("#tc").on("change", buscarBco);
$("#bco").on("change", buscarCta);


function buscarTc(){
    $("#Bco").html("<option value=''>Primero seleccione una Tarjeta</option>");
    
    $cia = $("#cia").val();
    
    if($cia == ""){
            $("#tc").html("<option value=''>Primero seleccione una Linea Aerea</option>");
    }
    else {
        $.ajax({
            dataType: "json",
            data: {"cia": $cia},
            url:   'buscar.php',
            type:  'post',
            beforeSend: function(){
                //Lo que se hace antes de enviar el formulario
                },
            success: function(respuesta){
                //lo que se si el destino devuelve algo
                $("#tc").html(respuesta.html);
            },
            error:    function(xhr,err){ 
                alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\n \n responseText: "+xhr.responseText);
            }
        });
    }
}

function buscarBco(){
    $("#bco").html("<option value=''>Primero seleccione una Tarjeta</option>");
    
    $tc = $("#tc").val();
    
    if($tc == ""){
            $("#tc").html("<option value=''>Primero seleccione una Linea Aerea</option>");
    }
    else {
        $.ajax({
            dataType: "json",
            data: {"tc": $tc},
            url:   'buscar.php',
            type:  'post',
            beforeSend: function(){
                //Lo que se hace antes de enviar el formulario
                },
            success: function(respuesta){
                //lo que se si el destino devuelve algo
                $("#bco").html(respuesta.html);
            },
            error:    function(xhr,err){ 
                alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\n \n responseText: "+xhr.responseText);
            }
        });
    }
}
function buscarCta(){
    $("#bco").html("<option value=''>Primero seleccione una Tarjeta</option>");
    
    $bco = $("#bco").val();
    
    if($tc == ""){
            $("#tc").html("<option value=''>Primero seleccione una Linea Aerea</option>");
    }
    else {
        $.ajax({
            dataType: "json",
            data: {"bco": $bco},
            url:   'buscar.php',
            type:  'post',
            beforeSend: function(){
                //Lo que se hace antes de enviar el formulario
                },
            success: function(respuesta){
                //lo que se si el destino devuelve algo
                $("#cta").html(respuesta.html);
            },
            error:    function(xhr,err){ 
                alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\n \n responseText: "+xhr.responseText);
            }
        });
    }
}
</script>
</body>
</html>
Saludos