<
%@LANGUAGE=
"VBSCRIPT" CODEPAGE=
"1252"%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=
"http://www.w3.org/1999/xhtml">
<meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1" />
<title>Combos combinados</title>
<%
dim strconn
strconn =
"Driver={SQL Server};Description=sqldemo;SERVER=(local); UID=sa;PWD=sa;DATABASE=ciscrmsc"
set conn = server.createobject
("adodb.connection")
conn.
open strconn
%>
<!-------------------------------------------------------
INICIA EL SCRIPT DEL LLENADO DE LOS COMBOS AUTOMÁTICOS
-------------------------------------------------------->
<script language =
"JavaScript">
//-------------------------------------------------------------------
//----------------------CIUDADES-------------------------------------
//-------------------------------------------------------------------
function trae_ciudad
(id_estado
)
{
//INICIALIZA LA VARIABLE lst_Estados CON LAS PROPIEDADES DEL OBJETO SELECT
var real=
0
var lst_Ciudades = document.forms
[0].sel_ciudades
var newOpt_ciudad
//CREA UN RECORDSET PARA ACCEDER A LA TABLA DE CIUDAD Y LLENA UNA VARIABLE PARA DETERMINAR EL NÚMERO DE CIUDADES
//QUE TIENE EL ESTADO SELECIONADO
<%
set rs = server.createobject
("adodb.recordset")
rs.
open "select estado,ciudad, nombre from sc_catciu order by nombre", conn
while not rs.
eof
%>
if (id_estado == <%=rs.fields
("estado")%>
)
{
real=real+
1
}
<%
rs.movenext
wend
rs.movefirst
%>
//CREA UN ARRAY DINÁMICO DE ACUERDO AL NÚMERO DE CIUDADES DETECTADAS POR EL ESTADO SELECCIONADO
//BORRA EL CONTENIDO DEL ARREGLO DINÁMICO
//SEGUIDO DE ESTO ELIMINA LAS VALORES DEL OBJETO
<OPTION> EN CASO DE QUE HUBIERA INFORMACIÓN
var ciudades=
new Array
(real-
1)
for (i =
0; i<=real ; i++
)
{
ciudades
[i
]=
""
}
while (lst_Ciudades.options.
length)
{
lst_Ciudades.options.remove
(0)
}
//INICIA UN CICLO PARA CREAR OBJETOS
"OPTIONS" Y ALMACENA LA INFORMACIÓN DEL ARRAY
"CIUDADES" EN CADA
//UNO DE ELLOS DEPENDIENDO DE LA CANTIDAD OBTENIDA EN EL CICLO ANTERIOR CON LA VARIABLE
"REAL"
<%
while not rs.
eof
%>
i=
0
var ciu
if (id_estado == <%=rs.fields
("estado")%>
)
{
ciu=
("<%=rs.fields("nombre
")%>")
ciudades
[i
]=ciu
newOpt_ciudad= document.createElement
("OPTION")
newOpt_ciudad.text= ciudades
[i
]
lst_Ciudades.options.add
(newOpt_ciudad
)
i=i+
1
}
<%
rs.movenext
wend
rs.Close
set rs=nothing
%>
}
//-------------------------------------------------------------------
//----------------------MUNICIPIOS-----------------------------------
//-------------------------------------------------------------------
function trae_municipios
(id_estado
)
{
var lst_Municipios = document.forms
[0].sel_municipios
var newOpt_municipios
var real =
0
<%
set rs = server.createobject
("adodb.recordset")
rs.
open "select estado, municipio, nombre from sc_catmuni ORDER BY nombre", conn
while not rs.
eof
%>
if (id_estado == <%=rs.fields
("estado")%>
)
{
real=real+
1
}
<%
rs.movenext
wend
rs.movefirst
%>
var municipios=
new Array
(real-
1)
for (i =
0; i<=real ; i++
)
{
municipios
[i
]=
""
}
while (lst_Municipios.options.
length)
{
lst_Municipios.options.remove
(0)
}
<%
while not rs.
eof
%>
i=
0
var mun
if (id_estado == <%=rs.fields
("estado")%>
)
{
mun=
("<%=rs.fields("nombre
")%>")
municipios
[i
]=mun
newOpt_municipios= document.createElement
("OPTION")
newOpt_municipios.text= municipios
[i
]
newOpt_municipios.value=
("<%=rs.fields("municipio
")%>")
lst_Municipios.options.add
(newOpt_municipios
)
i=i+
1
}
<%
rs.movenext
wend
rs.Close
set rs=nothing
%>
}
//-------------------------------------------------------------------
//----------------------COLONIAS-------------------------------------
//-------------------------------------------------------------------
//*************************************************************************************
function trae_colonias
(id_estado, id_municipio
)
{
var val_mpiodel
var real=
0
var newOpt_colonias
<%
dim Mun_Inicial
set rs_mun = server.createobject
("adodb.recordset")
rs_municipio.
open "select * from sc_catmuni", conn
while not rs_mun.
eof
rs_mun.movenext
wend
rs_mun.movefirst
%>
var mun=
new Array
(real-
1)
for (i =
0; i<=real ; i++
)
{
mun
[i
]=
""
}
while (lst_Municipios.options.
length)
{
lst_Municipios.options.remove
(0)
}
<%
while not rs_mun.
eof
%>
if (id_estado == <%=rs_mun.fields
("estado")%>
)
{
real=real+
1
}
<%
i=
0
var col
if (id_estado == <%=rs_mun.fields
("estado")%>
)
{
mun=
("<%=rs_mun.fields("estado
")%>")
mun
[i
]=col
newOpt_colonias= document.createElement
("OPTION")
newOpt_colonias.text= municipios
[i
]
newOpt_colonias.value=
("<%=rs_mun.fields("estado
")%>")
lst_Municipios.options.add
(newOpt_colonias
)
i=i+
1
}
<%
rs_municipio.movenext
wend
rs_municipio.Close
set rs=nothing
%>
}
///**************************************************************************************
</script>
<!-------------------------------------------------------
TERMINA EL SCRIPT DEL LLENADO DE LOS COMBOS AUTOMÁTICOS
-------------------------------------------------------->
<body>
<%
set rs_edos = server.createobject
("adodb.recordset")
rs_edos.
open "select distinct(nombre),id from sc_catedos", conn
%>
<form method=
"post">
Estados:
<select name=
"sel_estados" id=
"sel_estados" onchange=
"javascript:trae_ciudad(sel_estados.value);">
<%
while not rs_edos.
eof
%>
<option value=
"<%=rs_edos.fields("id
")%>"><%=rs_edos.fields
("nombre")%></option>
<%
rs_edos.movenext
wend
%>
</select>
<br>
Ciudades:
<select name=
"sel_ciudades" id=
"sel_ciudades" onchange=
"javascript:trae_municipios(sel_estados.value);">
<option>CIUDAD</option>
</select>
<br>
Municipio o Delegación:
<select name=
"sel_municipios" id=
"sel_municipios" onchange=
"javascript:trae_colonias(sel_estados.value, sel_municipios.value);">
<option>MUNICIPIO</option>
</select>
<br>
Colonia:
<select name=
"sel_colonias" id=
"sel_colonias" value=
"javascript:trae_colonias(sel_estados.value, sel_municipois.value);">
<option>COLONIA</option>
</select>
<br>
Código Postal:
<input name=
"cod_pos" type=
"text" value=
"CP">
</input>
<%
rs_edos=
close
conn.Close
set conn=nothing
%>
</form>
</body>
</html>