Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Select dependientes

Estas en el tema de Select dependientes en el foro de Frameworks JS en Foros del Web. Hola quiero hacer un select dependiente en donde al seleccionar el departamento (Matematicas, sociales, etc) te de una serie de opciones de materias (segun el ...
  #1 (permalink)  
Antiguo 02/09/2010, 05:58
 
Fecha de Ingreso: enero-2010
Mensajes: 128
Antigüedad: 14 años, 3 meses
Puntos: 2
Select dependientes

Hola quiero hacer un select dependiente en donde al seleccionar el departamento (Matematicas, sociales, etc) te de una serie de opciones de materias (segun el dpto elegido)

El problema es que el 2° select no carga.
Creo que el problema esta al usar esta instruccion: "getElementById", para hacer referencia al <select> me parece que tengo que usar otra, pero no estoy seguro, bueno GRACIAS.


Les dejo el codigo


Funciones de Ajax

Código:
function objetoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function carga_mat(dato){
	var divResultado=document.getElementById('destino');	
	var t4=document.getElementById('cod_dpto').value;
	ajax=objetoAjax();
	ajax.open("POST", dato);
	  ajax.onreadystatechange=function() {
        if (ajax.readyState==4) {
            divResultado.innerHTML = ajax.responseText;
        }
    }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("cod_dpto="+t4);	
	
}

cargaparcial.php
Código:
<?php
@session_start();
include ("funciones.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Red</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<script type="text/javascript" language="javascript" src="js/funciones.js"></script>

</head>
<script type="text/javascript" src="js/jquery.js"></script>

<?php


	if((isset($_SESSION['autorizado'])) AND ($_SESSION['autorizado']=TRUE)){

?>

	<form name="frmcargarparcial" action="cargarparcial.php" method="POST">
	<table>
	<td><tr> Seleccione Departamento: <select id="cod_dpto" name="cod_dpto" onchange="carga_mat('p_cargas.php'); return false">
<?php
		conectar();
		$consulta="SELECT codigo_dpto_uba, detalle FROM dpto";		
		$rowset=mysql_query ($consulta);		
		if(mysql_num_rows($rowset)){
			echo '<option value="-1">Selecciona un pais</option>';
			while($row = mysql_fetch_array($rowset)){			
				//echo "<p>".$row['nom_us']." - ".$row['ape_us']." - ".$row['tipo_doc_us']." - ".$row['id_us']."</p> \n <br>";		
				
				echo '<OPTION VALUE="'.$row['codigo_dpto_uba'].'" >'.$row['detalle'].'</OPTION>'; //Con esto puedo lograr que se autocomplete el option value.				
			}		
?>
		</select></tr>
		<tr><select id="destino" name="destino">
        
		
		</select></tr>
		</td>
		<input type="submit" value="Enviar"/>
		</table>
		</form >
<?php
		}
	}else{
		redirect ("index.php");
	}
?>

p_cargas.php
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Red</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />

</head>
<body>
<?php 
@session_start();
include ("funciones.php");
reg ("entre a p_cargas.php", "STATUS", "p_cargas.php");

//echo '<scrip> alert ('.$_POST['cod_dpto'].')</scrip>'

reg ($_POST['cod_dpto'], "STATUS", "p_cargas.php");
echo '<option value="-1">Selecciona una Materia</option>';
$consulta="SELECT codigo_mat_uba, detalle_mat_uba FROM materias WHERE codigo_dpto_uba='{$_POST['cod_dpto']}'";
$rowset=mysql_query ($consulta);
reg ($rowset, "STATUS", "p_cargas.php");
if(mysql_num_rows($rowset)){
	reg ("entre a p_cargas.php - WHILE", "STATUS", "p_cargas.php");
	while($row = mysql_fetch_array($rowset)){	
		echo '<option value="'.$row['codigo_mat_uba'].'" >'.$row['detalle_mat_uba'].'</option>'; //Con esto puedo lograr que se autocomplete el option value.				
	}
}
?>
</body>
</html>
  #2 (permalink)  
Antiguo 02/09/2010, 08:31
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Select dependientes

Hola

Mírate este y si te ayuda, perfecto!!
El problemas no parece ser el que indicas

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #3 (permalink)  
Antiguo 08/09/2010, 06:10
 
Fecha de Ingreso: enero-2010
Mensajes: 128
Antigüedad: 14 años, 3 meses
Puntos: 2
Respuesta: Select dependientes

Disculpame la demora, gracias por la rta.

Miré lo me mandaste, pero al final utilice las herramientas ajax de la librería jquery.
e hice un select principal y 2 dependientes.

Slds.

Etiquetas: ajax, dependientes, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:34.