Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/06/2007, 08:43
Avatar de edu007ar
edu007ar
 
Fecha de Ingreso: septiembre-2003
Ubicación: Buenos Aires
Mensajes: 118
Antigüedad: 21 años, 4 meses
Puntos: 0
Re: recordar checkbox tildados

hola... bueno no recibí respuesta pero ya lo pude solucionar, les paso la forma que encontré, combinando un poco de javascript, ajax y asp... así que no sé si lo querrán mover al foro de ajax....
de todas maneras como mucho de ajax no entiendo quizá se pueda depurar y mejorar bastante, pero así como está funciona...

pagina1.asp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status == 200) {
if (http.responseText.indexOf('invalid') == -1) {
//results = http.responseText.split(",");
//document.getElementById("campoMensaje").innerHTML = results[0];
document.getElementById("campoMensaje").innerHTML = http.responseText; //eliminar
enProceso = false;
}
}
}
}

function checkear(nombre) {
if (!enProceso && http) {
var valor = escape(document.getElementById(nombre).checked);
var url = "pagina3.asp?nombre="+ nombre +"&valor="+ valor;
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
enProceso = true;
http.send(null);
}
}

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

</script>

</head>

<body>
<%for i = 1 to 10%>
<input name="chk<%=i%>" type="checkbox" id="chk<%=i%>" value="si" onchange="checkear('chk<%=i%>');" <%if instr(session("a"),"chk"&i&",")>0 then%>checked<%end if%>>
<%next%>
<a href="pagina2.asp">Pagina 2
</a><br>
<div id="campoMensaje"><%=session("a")%></div>
</body>
</html>



pagina2.asp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status == 200) {
if (http.responseText.indexOf('invalid') == -1) {
//results = http.responseText.split(",");
//document.getElementById("campoMensaje").innerHTML = results[0];
document.getElementById("campoMensaje").innerHTML = http.responseText; //eliminar
enProceso = false;
}
}
}
}

function checkear(nombre) {
if (!enProceso && http) {
var valor = escape(document.getElementById(nombre).checked);
var url = "pagina3.asp?nombre="+ nombre +"&valor="+ valor;
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
enProceso = true;
http.send(null);
}
}

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

</script>

</head>

<body>
<%for i = 11 to 20%>
<input name="chk<%=i%>" type="checkbox" id="chk<%=i%>" value="si" onchange="checkear('chk<%=i%>');" <%if instr(session("a"),"chk"&i&",")>0 then%>checked<%end if%>>
<%next%>
<a href="pagina1.asp">Pagina 1 </a><br>
<div id="campoMensaje"><%=session("a")%></div>
</body>
</html>



pagina3.asp

<%'session("a")=""
nombre=request.querystring("nombre")
valor=request.querystring("valor")
yaEsta=false

if session("a")<>"" then '================================

activos=split(session("a"),",")
for i = 0 to ubound(activos)-1
temp=activos(i)
if temp=nombre and temp<>"" then
if valor="false" then
activos(i)=""
yaEsta=true
exit for
end if
end if
next

end if '================================================= =

if yaEsta=true then
session("a")=""
for i = 0 to ubound(activos)-1
temp=activos(i)
if temp<>"" then
session("a")=session("a")&temp&","
end if
next
else
if valor="true" then session("a")=session("a")&nombre&","
end if

response.write session("a")
%>



Espero que a alguno le sea de utilidad y se entienda para qué sirve..

Slds.
Eduardo