
12/12/2007, 09:55
|
| | Fecha de Ingreso: enero-2006
Mensajes: 233
Antigüedad: 19 años, 3 meses Puntos: 2 | |
Re: como hacer un list box a partir de otro ok...super,
mi prueba.asp
<!-- #include file ="../include/funciones.asp" -->
<%
Dim Conn
'ABRE CONEXION
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open CONNECTIONSTRING
'verifico que el querystring, no este vacio
if request.QueryString <>"" then
'tomo el valor del control, que contendra los datos
destino=request.QueryString("destino")
'tomo el valor de la categoria a buscar
categoria=request.QueryString("value")
'creo la consulta
strSQL = "SELECT idsubcategory,description FROM SUBCATEGORY where idcategory="&categoria&" "
'ejecucion
Set rst = Conn.Execute(strSQL)
'inicializo respuesta en blanco
respuesta=""
'de aki hasta el ultimo dato de la subcategoria
Do While Not rst.EOF
'por primera ves, tomo el valor simple
if respuesta="" then
respuesta= "<option value="""&rst("idsubcategory")&""" "&strSelected&">"&rst("description")&"</option>"
'en segundas vueltas, le anexo todos los valores que llegue a encontrar
else
respuesta="<option value="""&rst("idsubcategory")&""" "&strSelected&">"&rst("description")&"</option>"
end if
'me muevo al siguiente registro
rst.MoveNext
Loop
'esta parte permitira al control de ajax separar mediante el simbolo "|";
'el control de los datos
'en pocas palabras, esta parte es la importante
response.Write destino &"|"& respuesta
end if
%>
mi addproduct.asp
<!-- #include file ="../include/funciones.asp" -->
<%
'Dim fs, a, strRespuesta
Dim strNombreUsuario, strUsuarios
Dim Conn
'ABRE CONEXION
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open CONNECTIONSTRING
'VERIFICA EXISTENCIA DE SESION
Call ValidarSesion(TODOS)
strNombreUsuario = Session("NOMBRE")
respuesta=request.querystring("res")
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="include/style.css" type="text/css">
<script>
//NO MOVER ESTE CODIGO INFERIOR
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) { xmlhttp = false; }
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {xmlhttp = new XMLHttpRequest();
} catch (e) { xmlhttp = false; }
}return xmlhttp;}
var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
//NO MOVER EL CODIGO SUPERIOR
//PROCESO QUE INVOCARA EL METODO DE AJAX
function Consultas(destino,valor) {
if (!enProceso && http) {
var url = "prueba.asp?destino=" + destino + "&value=" + valor + "&guia="+ Math.random();;
http.open("GET", url, true);
http.onreadystatechange = GetData;
enProceso = true;
http.send(null);
}
}
function GetData(){
//proceso completado
if (http.readyState == 4) {
//sin error, se mandan datos al select
if (http.status == 200) {
//todo perfecto, escribiendolos
if (http.responseText.indexOf('invalid') == -1) {
//separamos el control de los datos
results = unescape(http.responseText.split("|"));
//results = http.responseText.split("|");
//en Results[0], estara el nombre del control que tendra los datos
//en Results[1], se encontraran todos los valores
document.getElementById(results[0]).innerHTML = results[1];
//Cerramos el proceso
enProceso = false;}}
//en caso de error
else{ alert("Error en la recepcion de datos")
enProceso = false;}}}
</script>
</head>
<body bgcolor="#ffffff" onLoad="" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#000099" vlink="#000099" alink="#000099">
<form name="form1" method="post" action="hhhhh.asp">
<table>
<tr>
<td colspan="2"> <div align="center"></div></td></tr>
<tr>
<td colspan="2"><hr align="center" width="100%" size="1" color="707e67"></td></tr>
<tr>
<td width="98"><strong>Descripción:</strong></td>
<td width="261"><div align="left"><input name="descripcion" type="text" class="InputBoxText" id="descripcion" size="75" maxlength="250"></div></td>
</tr>
<tr>
<td><strong>Category:</strong></td>
<td>
<select id="category" name="category" class="InputBoxText" onchange="Consultas('subcategory',this.value)" ><%
strSQL = "SELECT idcategory,description FROM Category order by description"
Set rst = Conn.Execute(strSQL)
Do While Not rst.EOF
strSelected = "selected"
Response.Write "<option value="""&rst("idcategory")&""" "&strSelected&">"&rst("description")&"</option>"
rst.MoveNext
Loop%>
</select>
</td>
</tr>
<tr>
<td><strong>SubCategory:</strong></td>
<td>
<select id="subcategory" name="subcategory" class="InputBoxText"></select>
</td></tr>
<tr>
<td><strong>Definition:</strong></td>
<td>
<textarea name="definition" cols="45" rows="3"></textarea></td>
</tr>
<tr>
<td colspan="2"><hr width="100%" size="1" color="707e67"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="enviar" type="button" class="boton_enviar" id="enviar" value="enviar" onclick="if (validar_forma()) {form1.submit();}">
</div></td>
</tr>
</table>
</body>
</html>
saludos |