
me funcionó perfecto en IE 8 Firefox y Mozilla
lo unico que he modificado es la programacion de DB ya que yo lo hago con dreamweaver todo lo demas igual
saludos y muchas gracias super util...
select_dependientes_3_niveles.asp
Código:
<!--#include file="Connections/conx.asp" -->
<%
sub generaselect()
'ABRO LA B/D
Dim DepartamentosRS
Dim DepartamentosRS_cmd
Dim DepartamentosRS_numRows
Set DepartamentosRS_cmd = Server.CreateObject ("ADODB.Command")
DepartamentosRS_cmd.ActiveConnection = MM_conx_STRING
DepartamentosRS_cmd.CommandText = "SELECT * FROM dbo.Tbl_departamento ORDER BY descripcion_departamento"
DepartamentosRS_cmd.Prepared = true
Set DepartamentosRS = DepartamentosRS_cmd.Execute
DepartamentosRS_numRows = 0
' Voy imprimiendo el primer select compuesto por los paises
Response.Write "<select class=""combo"" id=""select_1"" name=""paises"" onChange=""cargaContenido(2)"">"
Response.Write("<option value='0'>Seleccione departamento... </option>")
While not DepartamentosRS.EOF
Response.Write "<option value=""" & (DepartamentosRS.Fields.Item("departamento").Value) & """>" & Server.HTMLEncode(DepartamentosRS.Fields.Item("descripcion_departamento").Value) & "</option>"
DepartamentosRS.MoveNext
Wend
Response.Write "</select>"
DepartamentosRS.Close()
Set DepartamentosRS = Nothing
End sub
%>
<script language="javascript" type="text/javascript">
function nuevoAjax()
{
/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
lo que se puede copiar tal como esta aqui */
var xmlhttp=false;
try
{
// Creacion del objeto AJAX para navegadores no IE
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
// Creacion del objet AJAX para IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E) { xmlhttp=false; }
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }
return xmlhttp;
}
function cargaContenido(selectACargar)
{
// Recibo el número correspondiente al combo que se debe llenar de datos
var selectAnterior=selectACargar-1; // Obtengo el número del combo que activó el evento onChange
// Extraigo el valor del combo que se ha cambiado
var valor=document.getElementById("select_"+selectAnterior).options[document.getElementById("select_"+selectAnterior).selectedIndex].value;
var elemento;
if(valor!=0)
{
ajax=nuevoAjax();
// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
ajax.open("GET", "select_dependientes_3_niveles_proceso.asp?seleccionado="+valor+"&select_a_cargar="+selectACargar, true);
ajax.onreadystatechange=function()
{
if (ajax.readyState==1)
{
// Mientras carga elimino la opcion "Elige" y pongo una que dice "Cargando"
elemento=document.getElementById("select_"+selectACargar);
elemento.length=0;
var opcionCargando=document.createElement("option"); opcionCargando.value=0; opcionCargando.innerHTML="Cargando...";
elemento.appendChild(opcionCargando); elemento.disabled=true;
}
if (ajax.readyState==4)
{
// Coloco en la fila contenedora los datos que recivo del servidor
document.getElementById("fila_"+selectACargar).innerHTML=ajax.responseText;
}
}
ajax.send(null);
}
/* Colocamos mediante los whiles los selects en "Selecciona opción..." cuando el select anterior
ha quedado en estado "Elige" */
var x=1, y=null;
while(x<=2)
{
valor=document.getElementById("select_"+x).options[document.getElementById("select_"+x).selectedIndex].value;
if(valor==0)
{
while(x<=2)
{
y=x+1;
elemento=document.getElementById("select_"+y);
elemento.length=0;
var opcionSelecciona=document.createElement("option"); opcionSelecciona.value=0; opcionSelecciona.innerHTML="Seleccione distrito...";
elemento.appendChild(opcionSelecciona); elemento.disabled=true;
x++;
}
}
x++;
}
}
</script>
<style type="text/css">
.punteado
{
border-style:dotted;
border-color:#000000;
background-color:#EAEAEA;
font-family:Verdana;
font-size:10px;
text-align:center;
}
.combo
{
font-family:Verdana;
font-size:10px;
border-color:#CCCCCC;
}
</style>
</head>
<body>
<center>
<table border="1" width="600px" style="border-style:none;">
<tr>
<td id="fila_1" width="200px" class="punteado"><% generaSelect() %></td>
<td id="fila_2" width="200px" class="punteado">
<select class="combo" disabled="disabled" id="select_2" name="select_2">
<option id="valor_defecto" value="0">Seleccione provincia...</option>
</select>
</td>
<td id="fila_3" width="200px" class="punteado">
<select class="combo" disabled="disabled" id="select_3" name="select_3">
<option id="valor_defecto" value="0">Seleccione distrito...</option>
</select>
</td>
</tr>
</table>
</center>
</body>
</html>
select_dependientes_3_niveles_proceso.asp
Código:
<!--#include file="Connections/conx.asp" -->
<%
cod_a_buscar = Request.QueryString("seleccionado")
select_a_cargar = request.QueryString("select_a_cargar")
select case select_a_cargar
case 2 ' busco el estado
Dim ProvinciasRS
Dim ProvinciasRS_cmd
Dim ProvinciasRS_numRows
Set ProvinciasRS_cmd = Server.CreateObject ("ADODB.Command")
ProvinciasRS_cmd.ActiveConnection = MM_conx_STRING
ProvinciasRS_cmd.CommandText = "SELECT * FROM dbo.Tbl_provincia WHERE departamento="&cod_a_buscar&" ORDER BY descripcion_provincia"
ProvinciasRS_cmd.Prepared = true
Set ProvinciasRS = ProvinciasRS_cmd.Execute
ProvinciasRS_numRows = 0
response.Write "<select class='combo' id='select_"&select_a_Cargar&"' name='select_"&select_a_Cargar&"' onChange='cargaContenido(3)'>"
response.Write "<option value='0'>Seleccione provincia</option>"
While Not ProvinciasRS.EOF
' Imprimo las opciones del select
response.Write "<option value=""" & (ProvinciasRS.Fields.Item("provincia").Value)&"-"&(ProvinciasRS.Fields.Item("departamento").Value)& """>" & Server.HtmlEncode((ProvinciasRS.Fields.Item("descripcion_provincia").Value)) & "</option>"
ProvinciasRS.MoveNext
Wend
response.Write "</select>"
ProvinciasRS.Close()
Set ProvinciasRS = Nothing
case 3 'busco las poblaciones del estado
Dim DistritosRS
Dim DistritosRS_cmd
Dim DistritosRS_numRows
Set DistritosRS_cmd = Server.CreateObject ("ADODB.Command")
DistritosRS_cmd.ActiveConnection = MM_conx_STRING
DistritosRS_cmd.CommandText = "SELECT * FROM dbo.Tbl_distrito WHERE provincia+'-'+departamento='"&cod_a_buscar&"' ORDER BY descripcion_distrito"
DistritosRS_cmd.Prepared = true
Set DistritosRS = DistritosRS_cmd.Execute
DistritosRS_numRows = 0
response.Write "<select class='combo' id='select_"&select_a_Cargar&"' name='select_"&select_a_Cargar&"'>"
response.Write "<option value='0'>Seleccione distrito</option>"
While Not DistritosRS.EOF
' Imprimo las opciones del select
response.Write "<option value=""" & (DistritosRS.Fields.Item("distrito").Value) & """>" & Server.HtmlEncode((DistritosRS.Fields.Item("descripcion_distrito").Value)) & "</option>"
DistritosRS.MoveNext
Wend
response.Write "</select>"
DistritosRS.Close()
Set DistritosRS = Nothing
end select
%>