Foros del Web » Programando para Internet » ASP Clásico »

Pasar parametros de un select a otro!!!

Estas en el tema de Pasar parametros de un select a otro!!! en el foro de ASP Clásico en Foros del Web. Ke tal !! como puedo pasar el valor de una opcion de un select a otro pero el select. genera un consulta a una BD.. ...
  #1 (permalink)  
Antiguo 02/06/2005, 07:30
 
Fecha de Ingreso: febrero-2004
Ubicación: D.F.
Mensajes: 201
Antigüedad: 20 años, 3 meses
Puntos: 0
Pasar parametros de un select a otro!!!

Ke tal !!

como puedo pasar el valor de una opcion de un select a otro pero el select. genera un consulta a una BD..

primer select:
<select>
<option value="UBIC_TECN">UBICACION TECNICA</OPTION>
<option value="ETIQUETA">NOMBRE</OPTION>
</select>
que al momento de seleccionar una opcion me mande el valor a:

<select>
<%do while not Tabla.eof%>
<option value="<%=Tabla(valor seleccionado).value%>"><%=Tabla(valor seleccionado)%></option>
</select>

la consulta se hara de acuerdo al valor del campo que yo elija en el primer select..

graciasss
  #2 (permalink)  
Antiguo 02/06/2005, 07:40
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
hay muchas formas de hacerlo. esta es una de ellas.


Código:
 
<%
sSQL = "select * from catalogo_categorias order by titulo"
set RSCategorias = Master.Execute(sSQL)
%>
Código HTML:
<script language="javascript">
function cambiarcategoria(codcategoria) {
var f = document.form1
 
var subcategorias_tituo = new Array();
var subcategorias_codigo = new Array();
 
if (f.categorias.value != 0) {
<%
I = 0
if RSCategorias.bof=false and RSCategorias.eof=false then
	while not RSCategorias.eof
	 sSQL = "select * from catalogo_subcategorias where categoria=" & RSCategorias("codigo") & " and activado=true order by titulo"
	 set RSSubCategorias = Master.Execute(sSQL)
 
	 J = 0
	 response.Write("if (codcategoria == " & RSCategorias("codigo") & ") {") & vbcrlf
	 response.Write(vbtab & "f.subcategorias.options.length = 0;") & vbcrlf
	 response.Write(vbtab & "sub" & J & " = new Option(""Seleccione una Sub Categoría"",""0"",""defauldSelected"");") & vbcrlf
	 response.Write(vbtab & "f.subcategorias.options[" & J & "] = sub" & J & ";") & vbcrlf
	 J = J + 1
	 while not RSSubCategorias.eof
	 subc_codigo = RSSubCategorias("codigo")
	 subc_titulo = RSSubCategorias("titulo")
	 response.Write(vbtab & "sub" & J & " = new Option(""" & subc_titulo & """,""" & subc_codigo & ""","""");") & vbcrlf
	 response.Write(vbtab & "f.subcategorias.options[" & J & "] = sub" & J & ";") & vbcrlf
	 J = J + 1
	 RSSubCategorias.movenext
	 wend
 
	 response.Write("}") & vbcrlf
 
	 I = I + 1
	 RSCategorias.movenext
	wend
 
	RSCategorias.movefirst
end if
%>
} else {
f.subcategorias.options.length = 0;
sub0 = new Option("Seleccione una Sub Categoría","0","defauldSelected");
f.subcategorias.options[0] = sub0;
}
}
</script>
 
<form name="form1">
categorias
<select name="categorias" onChange="cambiarcategoria(this.value)">
<%
response.Write("<option value=""0"">Seleccione una Categoría</option>")
while not RSCategorias.eof
if RSCategorias("codigo") = categoria then
response.Write("<option value=""" & RSCategorias("codigo") & """ selected>" & RSCategorias("titulo") & "</option>")
else
response.Write("<option value=""" & RSCategorias("codigo") & """>" & RSCategorias("titulo") & "</option>")
end if
 
RSCategorias.movenext
wend
%>
</select>
 
subcategorias
<select name="subcategorias">
</select>
</form> 
saludos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #3 (permalink)  
Antiguo 02/06/2005, 12:02
 
Fecha de Ingreso: marzo-2005
Mensajes: 1.418
Antigüedad: 19 años, 2 meses
Puntos: 9
Lo que quieres hacer es un select dependiente?, mira si es eso, yo tengo esté código, por ahí te puede servir.

Código ASP-HTML

Dim IdCategoria

if Request.QueryString("id_cat") = "" then
IdCategoria = 1
else
IdCategoria = Request.QueryString("id_cat")
end if

set fst_combo = Server.CReateObject("ADODB.RecordSet")
fst_combo.Open "SELECT IdCat, Categoria FROM tabla_categorias", tu_conexion
%>
<Form Method="POST" action="something.asp" name="form1">
<Select name="categorias" onchange="update_combo()">
<option>[Seleccione una categoría]</option>
<%
do until fst_combo.EOF
%>
<option value="listas_desp.asp?id_cat=<%=RS("IdCat")%>"><% =RS("Categoria")%></option>
<%
fst_combo.MoveNext
loop
fst_combo.Close
set fst_combo = nothing
%>
</Select>
<%
set snd_combo = Server.CreateObject("ADODB.RecordSet")
snd_combo.Open "SELECT subCategoria FROM tabla_subCategorias WHERE IdCat_subCat = "&IdCategoria&"", tu_conexion
%>
<select name="subcategorias">
<%
do until snd_combo.EOf
%>
<option><%=snd_combo("subCategoria")%>
<%
snd_combo.MoveNext
Loop
snd_combo.Close
set snd_combo = nothing
%>
</select>
</Form>
</body>
</html>

Código Javascript

<script>
function update_combo(){
var selected_option = document.form1.categorias.options[document.form1.categorias.selectedIndex]
url = selected_option.value
selected_option.selected = true;
window.location = url;
}
</script>

El funcionamiento es muy sencillo, el segundo combo se actualiza de acuerdo al Id de la categoria que le paso por la URL, si el usuario entró por primera vez a la página, el Id de la categoria es por defecto es 1. Así de simple, lo que sí obviamente tendrás que adaptarlo a tus tablas, a tus datos, etc.
Saludos y espero que te haya sido de ayuda.
Suerte!.
  #4 (permalink)  
Antiguo 02/06/2005, 15:26
 
Fecha de Ingreso: febrero-2004
Ubicación: D.F.
Mensajes: 201
Antigüedad: 20 años, 3 meses
Puntos: 0
OK. probare.. esos ejemplos..

les aviso de los resultados
saludos
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 18:14.