![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
23/11/2006, 18:05
|
![Avatar de MrLake](http://static.forosdelweb.com/customavatars/avatar30788_1.gif) | | | Fecha de Ingreso: febrero-2003 Ubicación: México
Mensajes: 75
Antigüedad: 22 años Puntos: 0 | |
Tengo un script que hace lo que necesitas,
Se basa en que con asp se construye una cadena de texto que contiene las funciones de java que realizarán el filtrado de la información
Te lo mando como lo tengo pero si tienes problemas para entenderlo lo cambio con la estructura de tus tablas.
En este ejemplo la lista principal es la de clientes y la dependiente es la de proyectos, cuando un usuario selecciona un cliente se muetran solo los proyectos relacionados.
En tu caso sería que cuando se seleccione un país se muestren los precios de las regiones asociadas.
'*********************** Script de Java que reliza el llenado del combo dependiente
function addOpt(oCntrl, iPos, sTxt, sVal){
var selOpcion=new Option(sTxt, sVal);
eval(oCntrl.options[iPos]=selOpcion);
}
'*********************** Este es asp que construye el script con la información de la base de datos
'************************************************* *************************
'
'Arma la función para que las opciones de proyectos sean las que corresponden al cliente seleccionado
'
'Cargar los datos de la tabla del combo dependiente
Dim ixCliente
Dim ixProyecto
Dim iPos
Dim text
strSql = " select P.ClaveEmpresa, P.idProyecto, "
strSQL = strSQL & " P.Nombre "
strSQL = strSQL & " from Proyectos P, RecientesEmpleado ER"
strSQL = strSQL & " where P.idProyecto is not null "
strSQL = strSQL & " and P.idProyecto *= ER.idReciente "
strSQL = strSQL & " and ER.Empleado = " & Session("Empleado")
strSQL = strSQL & " and ER.TipoReciente = 2"
strSQL = strSQL & " order by P.ClaveEmpresa, ER.Fecha Desc,P.Nombre"
Cursor.Open strSql,Application("cnn_ConnectionString"),adOpenF orwardOnly,adLockReadOnly
set Cursor.ActiveConnection = nothing
'Arma la función del combo principal
text = "<script LANGUAGE='javascript'>"& chr(13)
text = text & "<!-- " & chr(13)
text = text & "function cambiaEmpresa(oCntrl){"& chr(13)
text = text & " document.formTiempos.cmboProyectos.length = 0;"
text = text & " switch (document.formTiempos.cmboEmpresas.value){" & chr(13)
text = text & " case '':" & chr(13)
text = text & " break;" & chr(13)
iPos=0
Do While Not Cursor.EOF
if ixCliente <> trim(Cursor("ClaveEmpresa")) then
if iPos > 0 then text = text & " break;" & chr(13)
text = text & " case '" & trim(Cursor("ClaveEmpresa")) & "':" & chr(13)
ixCliente = trim(Cursor("ClaveEmpresa"))
iPos = 0
end if
iPos = iPos + 1
text = text & " addOpt(oCntrl," & iPos & ",'" & Cursor("Nombre") & "', '" & Cursor("idProyecto") & "');" & chr(13)
Cursor.MoveNext
Loop
text = text & " break;" & chr(13)
text = text & " default:"
text = text & " document.formTiempos.cmboProyectos.length = 0;"
text = text & " addOpt(oCntrl," & 0 & ",'', '0');" & chr(13)
text = text & " }"& chr(13)
text = text & "}"& chr(13)
text = text & "//-->"& chr(13)
text = text & "</script>"
Response.Write text
Cursor.close
'***********************Fin del ASP
'********************** Lista Principal (Clientes)
<select name="cmboEmpresas" size="1" Class="Combo" onchange="cambiaEmpresa(document.formTiempos.cmboP royectos);"><%
strSql = " select C.ClaveEmpresa, "
strSQL = strSQL & " C.NombreComercial"
strSQL = strSQL & " from Clientes C, RecientesEmpleado ER "
strSQL = strSQL & " where C.idCliente *= ER.idReciente "
strSQL = strSQL & " and ER.TipoReciente = 1"
strSQL = strSQL & " and ER.Empleado = " & Session("Empleado")
strSQL = strSQL & " order by ER.Fecha Desc, NombreComercial Asc "
Cursor.Open strSql,Application("cnn_ConnectionString"),adOpenF orwardOnly,adLockReadOnly
set Cursor.ActiveConnection = nothing%>
<option value="0"> </option><%
Do While Not Cursor.EOF %>
<option value="<%=Cursor("ClaveEmpresa")%>" <%if trim(Cursor("ClaveEmpresa"))= trim(ClaveEmpresa) then %>Selected<%end if%>> <%=Cursor("NombreComercial")%>
</option><%
Cursor.MoveNext
Loop
Cursor.Close%>
</select>
'********************** Lista Relacionada (Proyectos)
<select name="cmboProyectos" size="1" Class="Combo" ><%
strSql = " select P.idProyecto, "
strSQL = strSQL & " Nombre"
strSQL = strSQL & " from Proyectos P, RecientesEmpleado ER"
strSQL = strSQL & " where P.idProyecto is not null "
strSQL = strSQL & " and P.idProyecto *= ER.idReciente "
strSQL = strSQL & " and ER.Empleado = " & Session("Empleado")
if ClaveEmpresa <> "" then
strSQL = strSQL & " and P.ClaveEmpresa = '" & ClaveEmpresa & "'"
else
strSQL = strSQL & " and P.ClaveEmpresa = '0'"
end if
strSQL = strSQL & " order by ER.Fecha Desc, P.Nombre"
Cursor.Open strSql,Application("cnn_ConnectionString"),adOpenF orwardOnly,adLockReadOnly
set Cursor.ActiveConnection = nothing%>
<option value="0"> </option><%
Do While Not Cursor.EOF %>
<option value="<%=Cursor("idProyecto")%>" <%if trim(Cursor("idProyecto"))= idProyecto then %>Selected<%end if%>> <%=Cursor("Nombre")%>
</option><%
Cursor.MoveNext
Loop
Cursor.Close%>
</select> |