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

Problema con ASP y Ajax

Estas en el tema de Problema con ASP y Ajax en el foro de ASP Clásico en Foros del Web. Buenas amigos de foros del web....tengo el siguiente problema.....resulta que tengo un formulario donde mediante ajax utilizo autocompletar para sugerir los modelos de productos que ...
  #1 (permalink)  
Antiguo 12/04/2010, 13:53
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Problema con ASP y Ajax

Buenas amigos de foros del web....tengo el siguiente problema.....resulta que tengo un formulario donde mediante ajax utilizo autocompletar para sugerir los modelos de productos que se encuentran almacenados....de ahí todo bien....el problema es que cuando el formulario tiene más de una "línea de venta" no funciona el autocompletar....
Esta es la imagen del formulario:



En este ejemplo...solo para la primera línea.. o sea la del CSR 80200 funciona el autocompletar....pero al seguir con el resto de los registros de abajo (del campo modelo) no funciona.....

Este es el código del formulario:

Ingreso.asp
Código ASP:
Ver original
  1. <%
  2.  
  3.     if Not IsEmpty(Request("distribuidor")) then
  4. DISTRIBUIDOR = Request("distribuidor")
  5.     end if
  6.  
  7.     if Not IsEmpty(Request("loc")) then
  8. LOC             = Request("loc")
  9.     end if
  10.    
  11.     if Not IsEmpty(Request("guia_d")) then
  12. GUIA_D = Request("guia_d")
  13.     end if
  14.    
  15.     if Not IsEmpty(Request("cod_auto")) then
  16. COD_AUTO = Request("cod_auto")
  17.     end if
  18.    
  19.  
  20. CANTIDAD    =Trim ( cdbl(Request("cantidad")) )
  21.  
  22. CSR_INI        =Trim ( cdbl(Request("csr_ini")) )
  23.  
  24. Actual     = date()
  25.  
  26. Set Cnn = Server.CreateObject( "ADODB.Connection" )
  27. Set RS = Server.CreateObject( "ADODB.Recordset" )
  28. Cnn.Open Session("cnx")
  29.  
  30. strSQL="SELECT distribuidor FROM Distribuidores where idDistribuidor='"&distribuidor&"'"
  31. set rs = Cnn.Execute(strSQL)
  32.  
  33. distribuidor = rs.Fields("distribuidor")
  34.  
  35. strSQL = "SELECT  ( "&CSR_INI&" + "&CANTIDAD&")-1  as CONTADOR"
  36. set rs= Cnn.Execute(strSQL)
  37.  
  38. %>
  39. <style type="text/css">
  40. <!--
  41. body {
  42.     background-image: url(../inventario/images/2x1900.jpg);
  43. }
  44. -->
  45.  
  46. #contenedor div.seleccionado {font-weight:bold; background:#F0F0F0; color:#black;}
  47. #contenedor div.deseleccionado {background:#FFFFFF; color:#000000;}
  48. #contenedor div{font:11px verdana; color:#000000; cursor:pointer; text-align:left; padding:2px 5px;}
  49.  
  50. .capa {
  51. background: #FFFFFF;
  52. border:1px solid rgb(120,120,120);
  53. width: 150px;
  54. _width: 250px;
  55. text-align: left;
  56. position: absolute;
  57. top: 30px;
  58. _top:38px;
  59. left: 117px;
  60. _left: 119px;
  61. }
  62. </style>
  63. <script type="text/javascript">
  64. var SelUsuario = {
  65.  
  66. Evento: function (elemento,nomevento,funcion) {
  67.   if (elemento.attachEvent)
  68.   {
  69.       var f=function(){
  70.         funcion.call(elemento,window.event);
  71.     }
  72.     elemento.attachEvent('on'+nomevento,f);
  73.     return true;
  74.   }
  75.   else  
  76.     if (elemento.addEventListener)
  77.     {
  78.       elemento.addEventListener(nomevento,funcion,false);
  79.       return true;
  80.     }
  81.     else
  82.       return false;
  83. },
  84.  
  85.  
  86.  
  87. init: function(){
  88. var elem1 = document.getElementById("txt");
  89. var elem2 = document.getElementById("contenedor");
  90.         SelUsuario.Evento(elem1, 'keyup', SelUsuario.Empieza);
  91.         SelUsuario.Evento(elem2, 'mouseover', SelUsuario.Seleccionar);
  92.         SelUsuario.Evento(elem1, 'keydown', SelUsuario.Pegar2);
  93.         SelUsuario.Evento(window, 'click', SelUsuario.Cerrar);
  94.     },
  95.  
  96.  
  97.  
  98.  
  99. creaAjax: function (){
  100.     var ajaxs = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLH TTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
  101.     var ajax = false;
  102.     for(var i=0 ; !ajax && i<ajaxs.length ; i++){
  103.         try{
  104.             ajax = new ActiveXObject(ajaxs[i]);   // Internet Explorer
  105.         }
  106.         catch(e) {
  107.             ajax = false;
  108.         }
  109.     }
  110.     if(!ajax && typeof XMLHttpRequest!='undefined') {
  111.         ajax = new XMLHttpRequest();  // Firefox, Opera 8.0+, Safari
  112.     }
  113.     return ajax;
  114. },
  115.  
  116. Empieza: function (ev) {
  117. var str = document.getElementById(this.id).value;
  118. var obj = document.getElementById("contenedor");
  119. var ref = obj.getElementsByTagName('DIV');
  120. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  121.  
  122.  
  123.  if (keyCode == 40) {
  124. //alert("flecha abajo")
  125.     SelUsuario.BajaOpt ()
  126.  } else if (keyCode == 38) {
  127. //alert("flecha arriba")
  128.     SelUsuario.SubeOpt ()
  129.  
  130.  
  131.  
  132.  
  133. } else if (keyCode == 13) {
  134.  
  135. for (var i = 0; i <= ref.length-1; i++) {
  136. if (ref[i].className == "seleccionado") {
  137.  
  138.         document.getElementById("txt").value = ref[i].id;
  139.         if (obj.style.display == "block"); obj.style.display= "none";
  140.         break;
  141.         }
  142.  
  143.     }
  144.  
  145.     try{ // DOM;
  146.         ev.preventDefault();
  147.         }catch(e){ // iexplore;
  148.         ev.returnValue = false;
  149.         }
  150.  
  151. } else {
  152.  
  153.     if (str.length < 2) {
  154.         //obj.innerHTML = "";
  155.         if (obj.style.display == "none")  obj.style.display= "none";
  156.                 else obj.style.display= "none";
  157.         return;
  158.     }
  159.     ajax = SelUsuario.creaAjax()
  160.     if (ajax==null) {
  161.         alert ("Tu navegador no soporta Ajax");
  162.         return;
  163.      }
  164. var url="sugest/SelecUsuarios.asp?q="+escape(str);
  165.     ajax.open("GET",url,true);
  166.     ajax.onreadystatechange = SelUsuario.Despliega;
  167.     //ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  168.             ajax.send(null);
  169.             return
  170. }
  171. },
  172.  
  173.  
  174.  
  175. Despliega: function () {
  176. var obj = document.getElementById("contenedor");
  177.    
  178.         if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3) {
  179.                                         obj.innerHTML = "<p align='center'><img src='../images/cargando.gif' border='0px' widht='15px' height='15px'/></p>";
  180.             obj.style.display= "block";
  181.                 }
  182.  
  183.                 else if (ajax.readyState==4) {
  184.             if (ajax.status==200) {
  185.             obj.innerHTML = unescape(ajax.responseText);
  186.  
  187.             }else {
  188.                                     obj.innerHTML = "<p>Se ha producido un error</p>";
  189.             }
  190.  
  191.         if (obj.style.display == "none")  obj.style.display= "block";
  192.         }
  193. },
  194.  
  195.  
  196.  
  197. Seleccionar: function () {
  198. var ref = document.getElementById(this.id).getElementsByTagName('DIV');
  199. //alert(ref);
  200. for (var i = 0; i < ref.length; i++) {
  201.  
  202. SelUsuario.Evento(ref[i], 'click', function() {
  203. SelUsuario.Pegar(this.id);
  204. //alert(this.id);
  205. })  
  206.  
  207.  
  208. SelUsuario.Evento(ref[i], 'mouseover',  function() {
  209. SelUsuario.Marcar(this.id);
  210. })
  211.  
  212. //SelUsuario.Evento(ref[i], 'mouseout',  function() {
  213. //SelUsuario.DesMarcar(this.id);
  214. //})
  215. }
  216. },
  217.  
  218.  
  219.  
  220. Pegar: function (valor) {
  221. //alert("el val " +valor);
  222. var obj = document.getElementById("contenedor")
  223.         document.getElementById("txt").value = valor;
  224.                 if (obj.style.display == "block"); obj.style.display= "none";      
  225. },
  226.  
  227.  
  228. Pegar2: function (ev) {
  229. var obj = document.getElementById("contenedor")
  230. var ref = obj.getElementsByTagName('DIV');
  231. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  232.  
  233. // enter 13 tab 9
  234. if ((keyCode == 13) || (keyCode == 9)) {
  235. //alert("enter")
  236.  
  237. for (var i = 0; i <= ref.length-1; i++) {
  238. if (ref[i].className == "seleccionado") {
  239.  
  240.         document.getElementById("txt").value = ref[i].id;
  241.         //window.focus();
  242.         if (obj.style.display == "block"); obj.style.display= "none";
  243. break;
  244. //alert(ref[i].id);
  245.  
  246.  
  247. }
  248. }
  249.  
  250. if (keyCode == 13) {
  251.     try{ // DOM;
  252.         ev.preventDefault();
  253.         }catch(e){ // iexplore;
  254.         ev.returnValue = false;
  255.         }
  256. }
  257.  
  258.  
  259. }  
  260. },
  261.  
  262.  
  263.  
  264.  
  265.  
  266. BajaOpt: function() {
  267. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  268. for (var i = 0; i <= ref.length-1; i++) {
  269. if (ref[i].className == "seleccionado") {
  270. ref[i].className = "deseleccionado";
  271. if (i < ref.length-1){
  272. i++;
  273. }else{
  274. i = 0;
  275. }
  276. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  277. ref[i].className = "seleccionado"
  278. }
  279. }
  280. },
  281.  
  282.  
  283. SubeOpt: function() {
  284. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  285. for (var i = 0; i <= ref.length-1; i++) {
  286. if (ref[i].className == "seleccionado") {
  287. ref[i].className = "deseleccionado";
  288. if (i < ref.length && i > 0){
  289. i--;
  290. }else{
  291. i = ref.length-1;
  292. }
  293. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  294. ref[i].className = "seleccionado"
  295. }
  296. }
  297. },
  298.  
  299.  
  300.  
  301. Marcar: function (id) {
  302. var selecionado = document.getElementById(id);
  303. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  304. for (var i = 0; i <= ref.length-1; i++) {
  305. if (ref[i].id != id) {
  306. ref[i].className = "deseleccionado";
  307. selecionado.className = "seleccionado";
  308. }
  309. }
  310. },
  311.  
  312. //DesMarcar: function (id) {
  313. //var ref = document.getElementById(id);
  314. //alert(ref);
  315. //ref.className = "deseleccionado"
  316. //alert("el " +id);        
  317. //},
  318.  
  319.  
  320. Cerrar: function () {  
  321. var obj = document.getElementById("contenedor")
  322.             if (obj.style.display == "block"); obj.style.display= "none";  
  323.    
  324. }
  325. }
  326.  
  327. SelUsuario.Evento(window, 'load', SelUsuario.init);
  328. </script>
  329. <form>
  330. <table width="430" height="103" border="1" align="center" bordercolor="#0000FF">
  331. <tr>
  332. <td width="213"><p>Distribuidor: <%=response.write (""&DISTRIBUIDOR&"") %></p>
  333. <p>Local: <%=response.write (""&LOC&"") %></p>
  334. <p>Fecha: <%=response.write (""&ACTUAL&"") %></p></td>
  335. <td width="130"><p>Gu&iacute;a de Despacho </p><p>N&ordm;: <%=response.write (""&GUIA_D&"") %></p></td>
  336. </tr>
  337. </table>
  338. <p align="center">&nbsp;</p>
  339.  
  340. <%For cuen = ""&CSR_INI&"" To ""&rs("CONTADOR")&"" Step 1%>
  341. <table width="351" border="1" align="center" bordercolor="#0000FF">
  342.  
  343. <tr>
  344. <td>Sel</td>  
  345. <td width="36">Csr:</td>
  346. <td width="70">Modelo:</td>
  347. <td width="47">Serie:</td>
  348. <td width="170">Comentarios:</td>
  349. </tr>
  350. <tr>
  351. <td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
  352. <td height="55"><input name="csr" readonly="readonly" size="3" value=<%=response.write (""&cuen&"") %> tabindex="2"></td>
  353. <td><input type="text" name="txt" id="txt" value="" autocomplete="off" tabindex="3"></td>
  354. <div id="contenedor" class="capa" class="vink" style="margin:5px 0px 0px 10px">
  355. <div id="contenedor" class="capa" style="display:none;"></div></div>
  356.  
  357. <td><input  name="serie" tabindex="4"></td>
  358. <td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
  359. </tr>
  360.  
  361. </table>
  362. <%next%>
  363. <p align="center">&nbsp;</p>
  364. </form>
  #2 (permalink)  
Antiguo 12/04/2010, 13:53
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Y este es el que extrae los valores de la base de datos:

SelecUsuarios.asp
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <%' Option Explicit %>
  3. <% Response.Buffer=True %>
  4. <% On Error Resume Next %>
  5. <%Response.charset="utf-8"%>
  6. <%
  7. Response.addHeader "pragma", "no-cache"
  8. Response.CacheControl = "Private"
  9. Response.Expires = -1000
  10. %>
  11. <%
  12. Dim SQL, rs, oConn, registros, i
  13. Dim usuario
  14. Dim nombre
  15. nombre = 0
  16. usuario = CStr(Request.QueryString("q"))
  17.  
  18.  
  19. IF Len(usuario) >= 2 then
  20. ' CONEXIÓN
  21.  
  22. set Cnn = Server.CreateObject("ADODB.Connection")
  23. set rs = Server.CreateObject ("ADODB.Recordset")
  24. Cnn.Open Session("cnx")
  25. SQL="SELECT DISTINCT ARTEFACTO FROM TBLCLIENTE where artefacto LIKE '"&usuario&"%' ORDER BY ARTEFACTO"
  26. set rs = Cnn.Execute(SQL)
  27. If not rs.eof then
  28. registros = rs.getrows()
  29. Else
  30. Response.Write "<p class=""deseleccionado""><strong>Sin resultados</strong></p>"
  31. Response.End ()
  32. End If
  33. rs.Close
  34. set rs = nothing
  35. Cnn.Close
  36. set oConn = nothing
  37. END IF
  38.  
  39. For i = 0 to Ubound(registros,2)
  40. If i = 0 then
  41. Response.Write "<div id="""& registros(nombre,i) &""" class=""seleccionado"">"& ResaltarSubStr(registros(nombre,i)) & "</div>"
  42. Else
  43. Response.Write "<div id="""& registros(nombre,i) &""" class="""">" & ResaltarSubStr(registros(nombre,i)) & "</div>"
  44. End If
  45. Next
  46.  
  47.  
  48. ' ========= Funciones ===========
  49. Function ResaltarSubStr(texto)
  50. Dim objRegExp
  51.  
  52. Set objRegExp= New RegExp
  53. objRegExp.IgnoreCase = True
  54. 'objRegExp.Global = True
  55.  
  56. objRegExp.Pattern = "\b("&usuario&")+(\w)"
  57. texto = objRegExp.Replace(texto, "<strong>$1</strong>$2")
  58.  
  59. Set objRegExp = Nothing
  60.  
  61. ResaltarSubStr = texto
  62.  
  63. End Function
  64. ' ========= Fin Funciones ===========
  65. %>

Eso....de antemano muchas gracias
  #3 (permalink)  
Antiguo 12/04/2010, 14:09
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

¿De qué me suena ese script?
Bueno le has añadido unos cuantos de campos más, no había pensado en ello, tendría que revisar el código, pero así a simple vista creo que lo que tendrías que hacer es modificar la función init, para sacar todos los campos. Es más bien un problema de javascript. Dame algo de tiempo e intento solucionarlo

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #4 (permalink)  
Antiguo 12/04/2010, 14:45
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Quizás de donde sera........jejejeje

Hojalá le puedas encontrar la solución Adler....o alguien más del foro....

Agradezco de antemano tu buena disposición para responder mis consultas....
Hasta pronto
  #5 (permalink)  
Antiguo 13/04/2010, 06:07
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Veamos si funciona

Has de modificar el HTML, te marco en negrita lo que has de modificar, si te fijas, usando el ciclo, le he puesto una id a la tabla, al input y div, ... alguna otra cosa también he modificado

Cita:
<form>
<table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_1">
<tr>
<td>Sel</td>
<td width="36">Csr:</td>
<td width="70">Modelo:</td>
<td width="47">Serie:</td>
<td width="170">Comentarios:</td>
</tr>
<tr>
<td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
<td height="55"><input type="text" name="csr" readonly="readonly" size="3" value="2345" tabindex="2"></td>
<td><input type="text" name="txt" id="txt_1" value="" autocomplete="off" tabindex="3"></td>
<div class="capa" class="vink" style="margin:5px 0px 0px 10px">
<div id="txt_1_contenedor" class="capa" style="display:none;"></div></div>
<td><input type="text" name="serie" tabindex="4"></td>
<td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
</tr>
</table>

<table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_2">
<tr>
<td>Sel</td>
<td width="36">Csr:</td>
<td width="70">Modelo:</td>
<td width="47">Serie:</td>
<td width="170">Comentarios:</td>
</tr>
<tr>
<td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
<td height="55"><input name="csr" readonly="readonly" size="3" value="2346" tabindex="2"></td>
<td><input type="text" name="txt" id="txt_2" value="" autocomplete="off" tabindex="3"></td>
<div class="capa" class="vink" style="margin:5px 0px 0px 10px">
<div id="txt_2_contenedor" class="capa" style="display:none;"></div></div>
<td><input name="serie" tabindex="4"></td>
<td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
</tr>
</table>
</form>
Ahora vamos al js

Te modifico la función init(). Fijate que elem1 y elem2 han pasado a ser inpt[2].id y inpt[2]_contenedor. El subindice 2 es la posición que ocupa el textbox con respecto al form que lo contiene

Código Javascript:
Ver original
  1. init: function(){
  2. tablas = document.body.getElementsByTagName('table');
  3. for (i=0; i < tablas.length; i++) {
  4. inpt = tablas[i].getElementsByTagName('input');
  5.         SelUsuario.Evento(inpt[2].id, 'keyup', SelUsuario.Empieza);
  6.         SelUsuario.Evento(inpt[2].id+ '_contenedor', 'mouseover', SelUsuario.Seleccionar);
  7.         SelUsuario.Evento(inpt[2].id, 'keydown', SelUsuario.Pegar2);
  8.         SelUsuario.Evento(window, 'click', SelUsuario.Cerrar);
  9. }
  10.     },

En la demás funciones, donde aparece
Cita:
document.getElementById('contenedor'); cambialo por document.getElementById(this.id+'_contenedor');
y donde aparece
Cita:
document.getElementById('txt') cambilo por document.getElementById(this.id);
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #6 (permalink)  
Antiguo 14/04/2010, 11:09
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Primero que todo gracias Adler por la pronta respuesta.
El problema es que yo dibujo las filas mediante un ciclo FOR....que de acuerdo a la cantidad solicitada, se despliegan en pantalla las filas necesarias me entiendes ?
Entonces con el código que me diste no aparece el ciclo FOR sino que dibujas dos tablas donde el campo que utiliza el autocompletar lo renombras como

Cita:
id="txt_1"
y
Cita:
id="txt_2"
Que podré hacer entonces ??

De antemano nuevamente gracias por tu tiempo y tu respuesta.
  #7 (permalink)  
Antiguo 14/04/2010, 11:25
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Cita:
Iniciado por darkmcloud Ver Mensaje
Primero que todo gracias Adler por la pronta respuesta.
El problema es que yo dibujo las filas mediante un ciclo FOR....que de acuerdo a la cantidad solicitada, se despliegan en pantalla las filas necesarias me entiendes ?
Es justamente lo que te comentaba. Usa el ciclo para darle una id distinta a cada tabla y a cada textbox. ¿O no he entendido cual es el problema? Ya dirás algo

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #8 (permalink)  
Antiguo 14/04/2010, 11:30
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Perdón por la ignorancia pero como hago para darle una id distinta a cada tabla y cada textbox?

Bueno, mejor creo que no existen preguntas tontas.....sino tontos que no preguntan......jejeje

Gracias nuevamente
  #9 (permalink)  
Antiguo 15/04/2010, 04:27
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Así, usando el ciclo

Cita:
<%For cuen = ""&CSR_INI&"" To ""&rs("CONTADOR")&"" Step 1%>
<table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_<%=cuen%>">
<tr>
<td>Sel</td>
<td width="36">Csr:</td>
<td width="70">Modelo:</td>
<td width="47">Serie:</td>
<td width="170">Comentarios:</td>
</tr>
<tr>
<td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
<td height="55"><input type="text" name="csr" readonly="readonly" size="3" value=<%=cuen%> tabindex="2"></td>
<td><input type="text" name="txt" id="txt_<%=cuen%>" value="" autocomplete="off" tabindex="3"></td>
<div id="contenedor_<%=cuen%>" class="capa" style="display:none;"></div></div>
<td><input type="text" name="serie" tabindex="4"></td>
<td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
</tr>
</table>
<%next%>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #10 (permalink)  
Antiguo 15/04/2010, 09:12
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Aqui estamos de nuevo Adler....

Hice todas las modificaciones que me dijiste pero ahora me aparece un error en el navegador que dice lo siguiente:
Cita:
Mensaje: 'inpt.2.id' es nulo o no es un objeto
Línea: 54
Carácter: 9
Código: 0
URI: http://localhost/bodega2/for.asp

En esa linea esta esto:
Cita:
SelUsuario.Evento(inpt[2].id, 'keyup', SelUsuario.Empieza);

Aquí está el código con todas las modificaciones que me dijiste que hiciera:

Código ASP:
Ver original
  1. <%@ Language=VBScript %>
  2. <% Response.addHeader " ", "no-cache" %>
  3. <% Response.CacheControl = "Private" %>
  4. <% Response.Expires=0 %>
  5. <% 
  6. CANTIDAD    =Trim ( cdbl(Request("cantidad")) )
  7.  
  8. CSR_INI     =Trim ( cdbl(Request("csr_ini")) )
  9.  
  10. Actual  = date()
  11.  
  12. Set Cnn = Server.CreateObject( "ADODB.Connection" )
  13. Set RS = Server.CreateObject( "ADODB.Recordset" )
  14. Cnn.Open Session("cnx")
  15.  
  16. strSQL="SELECT distribuidor FROM Distribuidores where idDistribuidor='"&distribuidor&"'"
  17. set rs = Cnn.Execute(strSQL)
  18.  
  19. distribuidor = rs.Fields("distribuidor")
  20.  
  21. strSQL = "SELECT  ( "&CSR_INI&" + "&CANTIDAD&")-1  as CONTADOR"
  22. set rs= Cnn.Execute(strSQL)
  23.  
  24. %>
  25. <style type="text/css">
  26. <!--
  27. body {
  28.     background-image: url(../inventario/images/2x1900.jpg);
  29. }
  30. -->
  31. #contenedor div.seleccionado {font-weight:bold; background:#F0F0F0; color:#black;}
  32. #contenedor div.deseleccionado {background:#FFFFFF; color:#000000;}
  33. #contenedor div{font:11px verdana; color:#000000; cursor:pointer; text-align:left; padding:2px 5px;}
  34.  
  35. .capa {
  36. background: #FFFFFF;
  37. border:1px solid rgb(120,120,120);
  38. width: 150px;
  39. _width: 250px;
  40. text-align: left;
  41. position: absolute;
  42. top: 30px;
  43. _top:38px;
  44. left: 117px;
  45. _left: 119px;
  46. }
  47. </style>
  48. <script type="text/javascript">
  49. var SelUsuario = {
  50.  
  51. Evento: function (elemento,nomevento,funcion) {
  52.   if (elemento.attachEvent)
  53.   {
  54.       var f=function(){
  55.         funcion.call(elemento,window.event);
  56.     }
  57.     elemento.attachEvent('on'+nomevento,f);
  58.     return true;
  59.   }
  60.   else  
  61.     if (elemento.addEventListener)
  62.     {
  63.       elemento.addEventListener(nomevento,funcion,false);
  64.       return true;
  65.     }
  66.     else
  67.       return false;
  68. },
  69.  
  70.  
  71. init: function(){
  72. tablas = document.body.getElementsByTagName('table');
  73. for (i=0; i < tablas.length; i++) {
  74. inpt = tablas[i].getElementsByTagName('input');
  75.         SelUsuario.Evento(inpt[2].id, 'keyup', SelUsuario.Empieza);
  76.         SelUsuario.Evento(inpt[2].id+ '_contenedor', 'mouseover', SelUsuario.Seleccionar);
  77.         SelUsuario.Evento(inpt[2].id, 'keydown', SelUsuario.Pegar2);
  78.         SelUsuario.Evento(window, 'click', SelUsuario.Cerrar);
  79. }
  80.     },
  81.  
  82.  
  83.  
  84. creaAjax: function (){
  85.     var ajaxs = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLH TTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
  86.     var ajax = false;
  87.     for(var i=0 ; !ajax && i<ajaxs.length ; i++){
  88.         try{
  89.             ajax = new ActiveXObject(ajaxs[i]);   // Internet Explorer
  90.         }
  91.         catch(e) {
  92.             ajax = false;
  93.         }
  94.     }
  95.     if(!ajax && typeof XMLHttpRequest!='undefined') {
  96.         ajax = new XMLHttpRequest();  // Firefox, Opera 8.0+, Safari
  97.     }
  98.     return ajax;
  99. },
  100.  
  101. Empieza: function (ev) {
  102. var str = document.getElementById(this.id).value;
  103. var obj = document.getElementById(this.id+'_contenedor');
  104. var ref = obj.getElementsByTagName('DIV');
  105. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  106.  
  107.  
  108.  if (keyCode == 40) {
  109. //alert("flecha abajo")
  110.     SelUsuario.BajaOpt ()
  111.  } else if (keyCode == 38) {
  112. //alert("flecha arriba")
  113.     SelUsuario.SubeOpt ()
  114.  
  115.  
  116.  
  117.  
  118. } else if (keyCode == 13) {
  119.  
  120. for (var i = 0; i <= ref.length-1; i++) {
  121. if (ref[i].className == "seleccionado") {
  122.  
  123.         document.getElementById(this.id).value = ref[i].id;
  124.         if (obj.style.display == "block"); obj.style.display= "none";
  125.         break;
  126.         }
  127.  
  128.     }
  129.  
  130.     try{ // DOM;
  131.         ev.preventDefault();
  132.         }catch(e){ // iexplore;
  133.         ev.returnValue = false;
  134.         }
  135.  
  136. } else {
  137.  
  138.     if (str.length < 2) {
  139.         //obj.innerHTML = "";
  140.         if (obj.style.display == "none")  obj.style.display= "none";
  141.                 else obj.style.display= "none";
  142.         return;
  143.     }
  144.     ajax = SelUsuario.creaAjax()
  145.     if (ajax==null) {
  146.         alert ("Tu navegador no soporta Ajax");
  147.         return;
  148.      }
  149. var url="sugest/SelecUsuarios.asp?q="+escape(str);
  150.     ajax.open("GET",url,true);
  151.     ajax.onreadystatechange = SelUsuario.Despliega;
  152.     //ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  153.             ajax.send(null);
  154.             return
  155. }
  156. },
  157.  
  158.  
  159.  
  160. Despliega: function () {
  161. var obj = document.getElementById(this.id+'_contenedor');
  162.    
  163.         if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3) {
  164.                                         obj.innerHTML = "<p align='center'><img src='../images/cargando.gif' border='0px' widht='15px' height='15px'/></p>";
  165.             obj.style.display= "block";
  166.                 }
  167.  
  168.                 else if (ajax.readyState==4) {
  169.             if (ajax.status==200) {
  170.             obj.innerHTML = unescape(ajax.responseText);
  171.  
  172.             }else {
  173.                                     obj.innerHTML = "<p>Se ha producido un error</p>";
  174.             }
  175.  
  176.         if (obj.style.display == "none")  obj.style.display= "block";
  177.         }
  178. },
  179.  
  180. Seleccionar: function () {
  181. var ref = document.getElementById(this.id).getElementsByTagName('DIV');
  182. //alert(ref);
  183. for (var i = 0; i < ref.length; i++) {
  184.  
  185. SelUsuario.Evento(ref[i], 'click', function() {
  186. SelUsuario.Pegar(this.id);
  187. //alert(this.id);
  188. })  
  189.  
  190.  
  191. SelUsuario.Evento(ref[i], 'mouseover',  function() {
  192. SelUsuario.Marcar(this.id);
  193. })
  194.  
  195. //SelUsuario.Evento(ref[i], 'mouseout',  function() {
  196. //SelUsuario.DesMarcar(this.id);
  197. //})
  198. }
  199. },
  200.  
  201.  
  202.  
  203. Pegar: function (valor) {
  204. //alert("el val " +valor);
  205. var obj = document.getElementById(this.id+'_contenedor')
  206.         document.getElementById(this.id).value = valor;
  207.                 if (obj.style.display == "block"); obj.style.display= "none";      
  208. },
  209.  
  210.  
  211. Pegar2: function (ev) {
  212. var obj = document.getElementById(this.id+'_contenedor')
  213. var ref = obj.getElementsByTagName('DIV');
  214. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  215.  
  216. // enter 13 tab 9
  217. if ((keyCode == 13) || (keyCode == 9)) {
  218. //alert("enter")
  219.  
  220. for (var i = 0; i <= ref.length-1; i++) {
  221. if (ref[i].className == "seleccionado") {
  222.  
  223.         document.getElementById(this.id).value = ref[i].id;
  224.         //window.focus();
  225.         if (obj.style.display == "block"); obj.style.display= "none";
  226. break;
  227. //alert(ref[i].id);
  228.  
  229.  
  230. }
  231. }
  232.  
  233. if (keyCode == 13) {
  234.     try{ // DOM;
  235.         ev.preventDefault();
  236.         }catch(e){ // iexplore;
  237.         ev.returnValue = false;
  238.         }
  239. }
  240.  
  241.  
  242. }  
  243. },
  244.  
  245.  
  246. BajaOpt: function() {
  247. var ref = document.getElementById(this.id+'_contenedor').getElementsByTagName('DIV');
  248. for (var i = 0; i <= ref.length-1; i++) {
  249. if (ref[i].className == "seleccionado") {
  250. ref[i].className = "deseleccionado";
  251. if (i < ref.length-1){
  252. i++;
  253. }else{
  254. i = 0;
  255. }
  256. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  257. ref[i].className = "seleccionado"
  258. }
  259. }
  260. },
  261.  
  262.  
  263. SubeOpt: function() {
  264. var ref = document.getElementById(this.id+'_contenedor').getElementsByTagName('DIV');
  265. for (var i = 0; i <= ref.length-1; i++) {
  266. if (ref[i].className == "seleccionado") {
  267. ref[i].className = "deseleccionado";
  268. if (i < ref.length && i > 0){
  269. i--;
  270. }else{
  271. i = ref.length-1;
  272. }
  273. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  274. ref[i].className = "seleccionado"
  275. }
  276. }
  277. },
  278.  
  279. Marcar: function (id) {
  280. var selecionado = document.getElementById(id);
  281. var ref = document.getElementById(this.id+'_contenedor').getElementsByTagName('DIV');
  282. for (var i = 0; i <= ref.length-1; i++) {
  283. if (ref[i].id != id) {
  284. ref[i].className = "deseleccionado";
  285. selecionado.className = "seleccionado";
  286. }
  287. }
  288. },
  289.  
  290. //DesMarcar: function (id) {
  291. //var ref = document.getElementById(id);
  292. //alert(ref);
  293. //ref.className = "deseleccionado"
  294. //alert("el " +id);        
  295. //},
  296.  
  297.  
  298. Cerrar: function () {  
  299. var obj = document.getElementById(this.id+'_contenedor')
  300.             if (obj.style.display == "block"); obj.style.display= "none";  
  301.    
  302. }
  303. }
  304.  
  305. SelUsuario.Evento(window, 'load', SelUsuario.init);
  306. </script>
  307. <form>
  308. <table width="430" height="103" border="1" align="center" bordercolor="#0000FF">
  309. <tr>
  310. <td width="213"><p>Distribuidor: <%=response.write (""&DISTRIBUIDOR&"") %></p>
  311. <p>Local: <%=response.write (""&LOC&"") %></p>
  312. <p>Fecha: <%=response.write (""&ACTUAL&"") %></p></td>
  313. <td width="130"><p>Gu&iacute;a de Despacho </p><p>N&ordm;: <%=response.write (""&GUIA_D&"") %></p></td>
  314. </tr>
  315. </table>
  316. <p align="center">&nbsp;</p>
  317. <%For cuen = ""&CSR_INI&"" To ""&rs("CONTADOR")&"" Step 1%>
  318. <table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_<%=cuen%>">
  319. <tr>
  320. <td>Sel</td>
  321. <td width="36">Csr:</td>
  322. <td width="70">Modelo:</td>
  323. <td width="47">Serie:</td>
  324. <td width="170">Comentarios:</td>
  325. </tr>
  326. <tr>
  327. <td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
  328. <td height="55"><input type="text" name="csr" readonly="readonly" size="3" value=<%=cuen%> tabindex="2"></td>
  329. <td><input type="text" name="txt" id="txt_<%=cuen%>" value="" autocomplete="off" tabindex="3"></td>
  330. <div id="contenedor_<%=cuen%>" class="capa" style="display:none;"></div></div>
  331. <td><input type="text" name="serie" tabindex="4"></td>
  332. <td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
  333. </tr>
  334. </table>
  335. <%next%>
  336. <p align="center">&nbsp;</p>
  337. </form>


De antemano muchas gracias
  #11 (permalink)  
Antiguo 16/04/2010, 06:50
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Se me paso, prueba ahora

Cita:
SelUsuario.Evento(document.getElementById(inpt[2].id), 'keyup', SelUsuario.Empieza);
a los demás los llamas igual

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #12 (permalink)  
Antiguo 16/04/2010, 08:42
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Sigue dando error en la misma linea Adler.....asi deje la funcion:

Cita:
init: function(){
tablas = document.body.getElementsByTagName('table');
for (i=0; i < tablas.length; i++) {
inpt = tablas[i].getElementsByTagName('input');

SelUsuario.Evento(document.getElementById(inpt[2].id), 'keyup', SelUsuario.Empieza);
SelUsuario.Evento(inpt[2].id+ '_contenedor', 'mouseover', SelUsuario.Seleccionar);
SelUsuario.Evento(inpt[2].id, 'keydown', SelUsuario.Pegar2);
SelUsuario.Evento(window, 'click', SelUsuario.Cerrar);
}
},
No quise modificar los demás porque sigue dando error en la misma linea.

De antemano muchas gracias
  #13 (permalink)  
Antiguo 17/04/2010, 20:59
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Y alguna solucion Adler o alguien por favor ???
  #14 (permalink)  
Antiguo 19/04/2010, 14:37
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Ten paciencia, hay mas cosas aparte de esto

Se podría optimizar, pero ya me canse

Código Javascript:
Ver original
  1. <STYLE TYPE="text/css">
  2. #contenedorOpt div.seleccionado {font-weight:bold; background:#F0F0F0; color:#FF6600;}
  3. #contenedorOpt div.deseleccionado {background:#FFFFFF; color:#000000;}
  4. #contenedorOpt div {font:11px verdana; color:#000000; cursor:pointer; text-align:left; padding:2px 5px;}
  5.  
  6. .capa {
  7. background: #FFFFFF;
  8. border:1px solid rgb(120,120,120);
  9. width: 144px;
  10. _width: 146px;
  11. text-align: left;
  12. position: absolute;
  13. }
  14. </STYLE>
  15. <script type="text/javascript">
  16. var ns4 = (document.layers)? true:false
  17. var ie4 = (document.all)? true:false
  18. var ns6 = (document.getElementById)? true:false
  19. var TxtId = '';
  20.  
  21. var SelUsuario = {
  22.  
  23. captura_objeto : function(idnombre) {
  24.     if (ns6) {
  25.         return document.getElementById(idnombre);
  26.     }else if (ie4){
  27.         return document.all[idnombre];
  28.     }else if (ns4){
  29.         return document.layers[idnombre];
  30.     }else{
  31.         return null;
  32.     }
  33. },
  34.  
  35.  
  36. Evento: function (elemento,nomevento,funcion) {
  37.     if (elemento.attachEvent) {
  38.             var f=function() {
  39.                 funcion.call(elemento,window.event);
  40.             }
  41.             elemento.attachEvent('on'+nomevento,f);
  42.             return true;
  43.     } else if (elemento.addEventListener) {
  44.             elemento.addEventListener(nomevento,funcion,false);
  45.             return true;
  46.         }else{
  47.             return false;
  48.     }
  49. },
  50.  
  51.  
  52. creaAjax: function (){
  53. var ajaxs = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLH TTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
  54. var ajax = false;
  55.     for(var i=0 ; !ajax && i<ajaxs.length ; i++){
  56.         try{
  57.             ajax = new ActiveXObject(ajaxs[i]);   // Internet Explorer
  58.         }
  59.         catch(e) {
  60.             ajax = false;
  61.         }
  62.     }
  63.     if(!ajax && typeof XMLHttpRequest!='undefined') {
  64.         ajax = new XMLHttpRequest();  // Firefox, Opera 8.0+, Safari
  65.     }
  66.     return ajax;
  67. },
  68.  
  69.  
  70. init: function(){
  71. var tablas = document.body.getElementsByTagName('table');
  72.     for (i=0; i < tablas.length; i++) {
  73.         var inpt = tablas[i].getElementsByTagName('input');
  74.                 SelUsuario.Evento(SelUsuario.captura_objeto(inpt[2].id), 'keyup', SelUsuario.Empieza);
  75.                 SelUsuario.Evento(SelUsuario.captura_objeto('contenedorOpt'), 'mouseover', SelUsuario.Seleccionar);
  76.             SelUsuario.Evento(SelUsuario.captura_objeto(inpt[2].id), 'keydown', SelUsuario.Pegar2);
  77.                 SelUsuario.Evento(SelUsuario.captura_objeto(inpt[2].id), 'blur', SelUsuario.Cerrar);
  78.     }
  79. },
  80.  
  81.  
  82.  
  83. PosicionAbsolutaElemento: function(elTxtBox)  {
  84.     if (typeof elTxtBox == "string")
  85.         var elTxtBox = SelUsuario.captura_objeto(elTxtBox);
  86.             if (!elTxtBox) return { top:0,left:0 };
  87.         var y = 0;
  88.         var x = 0;
  89.             while (elTxtBox.offsetParent) {
  90.                     x += elTxtBox.offsetLeft;
  91.                     y += elTxtBox.offsetTop;
  92.                 elTxtBox = elTxtBox.offsetParent;
  93.             }
  94.         return {top:y,left:x};
  95.  
  96. },
  97.  
  98.  
  99. Desplieaga: function(posLeft,posTop) {
  100. var elDiv = SelUsuario.captura_objeto('contenedorOpt');
  101.     elDiv.style.left = posLeft+'px';
  102.     elDiv.style.top = parseInt(posTop+21) +'px';
  103.             elDiv.style.display = 'block';
  104.     elDiv.style.zIndex = 100;
  105. },
  106.  
  107.  
  108. Empieza: function (ev) {
  109. TxtId = SelUsuario.captura_objeto(this.id).id;
  110. var elTxtBox = SelUsuario.captura_objeto(this.id);
  111. var str = elTxtBox.value;
  112. var elDiv = SelUsuario.captura_objeto('contenedorOpt');
  113. var opt = elDiv.getElementsByTagName('DIV');
  114. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  115.  
  116.     if (keyCode == 40) {
  117.         SelUsuario.BajaOpt ('contenedorOpt')
  118.     }else if (keyCode == 38) {
  119.         SelUsuario.SubeOpt ('contenedorOpt')
  120.     }else if (keyCode == 13) {
  121.  
  122.         for (var i = 0; i <= opt.length-1; i++) {
  123.  
  124.             if (opt[i].className == "seleccionado") {
  125.                 str = opt[i].id;
  126.                 if (elDiv.style.display == "block"); elDiv.style.display= "none";
  127.         break;
  128.                 }
  129.             }
  130.  
  131.         try{ // DOM;
  132.             ev.preventDefault();
  133.         }catch(e){ // iexplore;
  134.             ev.returnValue = false;
  135.         }
  136.     } else {
  137.  
  138.         if (str.length < 2) {
  139.             if (elDiv.style.display == "none")  elDiv.style.display= "none";
  140.                     else elDiv.style.display= "none";  
  141.             return;
  142.         }
  143.         ajax = SelUsuario.creaAjax()
  144.  
  145.         if (ajax==null) {
  146.             alert ("Tu navegador no soporta Ajax");
  147.             return;
  148.         }
  149.  
  150. var url="SelecUsuarios.php?q="+escape(str);
  151. ajax.open("GET",url,true);
  152. ajax.onreadystatechange = function () {
  153. var PosElemento = SelUsuario.PosicionAbsolutaElemento(elTxtBox);
  154. var posicionInicialLeft = parseInt(PosElemento.left);
  155. var posicionInicialTop = parseInt(PosElemento.top);
  156.  
  157.         if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3) {
  158.                                         elDiv.innerHTML = "<p align='center'><img src='precarga.gif' border='0px' widht='15px' height='15px'/></p>";
  159.             elDiv.style.display= "block";
  160.  
  161.                 }else if (ajax.readyState==4) {
  162.             if (ajax.status==200) {
  163.                 elDiv.innerHTML = unescape(ajax.responseText);
  164.             }else {
  165.                                         elDiv.innerHTML = "<p>Se ha producido un error</p>";
  166.             }
  167.  
  168.         if (elDiv.style.display == "none")  elDiv.style.display= "block";
  169.         }
  170.     SelUsuario.Desplieaga(posicionInicialLeft, posicionInicialTop);
  171.     }
  172.             ajax.send(null);
  173.             return
  174. }
  175. },
  176.  
  177.  
  178. Seleccionar: function () {
  179. var opt = SelUsuario.captura_objeto('contenedorOpt').getElementsByTagName('DIV');
  180.     for (var i = 0; i < opt.length; i++) {
  181.         SelUsuario.Evento(opt[i], 'click', function() {SelUsuario.Pegar(this.id);})  
  182.         SelUsuario.Evento(opt[i], 'mouseover',  function() {SelUsuario.Marcar(this.id);})
  183.     }
  184. },
  185.  
  186.  
  187.  
  188. Pegar: function (valor) {
  189. var elDiv = SelUsuario.captura_objeto('contenedorOpt')
  190.     SelUsuario.captura_objeto(TxtId).value = valor;
  191.             if (elDiv.style.display == "block"); elDiv.style.display= "none";      
  192. },
  193.  
  194.  
  195.  
  196. Marcar: function (valor) {
  197. var selecionado = SelUsuario.captura_objeto(valor);
  198. var opt = SelUsuario.captura_objeto('contenedorOpt').getElementsByTagName('DIV');
  199.     for (var i = 0; i < opt.length; i++) {
  200.         if (opt[i].className == "seleccionado") {
  201.             opt[i].className = "deseleccionado";
  202.             selecionado.className = "seleccionado";
  203.     break;
  204.         }
  205.     }
  206. },
  207.  
  208.  
  209. Pegar2: function (ev) {
  210. var elDiv = SelUsuario.captura_objeto('contenedorOpt')
  211. var opt = elDiv.getElementsByTagName('DIV');
  212. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  213.  
  214.     if ((keyCode == 13) || (keyCode == 9)) {
  215.         for (var i = 0; i <= opt.length-1; i++) {
  216.             if (opt[i].className == "seleccionado") {
  217.                 SelUsuario.captura_objeto(this.id).value = opt[i].id;
  218.                 if (elDiv.style.display == "block"); elDiv.style.display= "none";
  219.                     break;
  220.             }
  221.         }
  222.  
  223.         if (keyCode == 13) {
  224.             try{ // DOM;
  225.                 ev.preventDefault();
  226.             }catch(e){ // iexplore;
  227.                 ev.returnValue = false;
  228.             }
  229.         }
  230.     }  
  231. },
  232.  
  233.  
  234.  
  235. BajaOpt: function() {
  236. var opt = SelUsuario.captura_objeto('contenedorOpt').getElementsByTagName('DIV');
  237.     for (var i = 0; i <= opt.length-1; i++) {
  238.         if (opt[i].className == "seleccionado") {
  239.             opt[i].className = "deseleccionado";
  240.             if (i < opt.length-1){
  241.                 i++;
  242.             }else{
  243.                 i = 0;
  244.             }
  245.             opt[i].className = "seleccionado"
  246.         }
  247.     }
  248. },
  249.  
  250.  
  251. SubeOpt: function() {
  252. var opt = SelUsuario.captura_objeto('contenedorOpt').getElementsByTagName('DIV');
  253.     for (var i = 0; i <= opt.length-1; i++) {
  254.         if (opt[i].className == "seleccionado") {
  255.             opt[i].className = "deseleccionado";
  256.             if (i < opt.length && i > 0){
  257.                 i--;
  258.             }else{
  259.                 i = opt.length-1;
  260.             }
  261.             opt[i].className = "seleccionado"
  262.         }
  263.     }
  264. },
  265.  
  266.  
  267. Cerrar: function () {
  268. setTimeout("var elDiv = SelUsuario.captura_objeto('contenedorOpt'); if (elDiv.style.display == 'block'); elDiv.style.display= 'none';", 1000);
  269. }
  270.  
  271. }
  272. SelUsuario.Evento(window, 'load', SelUsuario.init);
  273. </script>

En el HTML tendrás que hacer algunos cambios, nada de importancia, te los marco

Cita:
<form method="post" action="">

<table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_1">
<tr>
<td>Sel</td>
<td width="36">Csr:</td>
<td width="70">Modelo:</td>
<td width="47">Serie:</td>
<td width="170">Comentarios:</td>
</tr>
<tr>
<td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
<td height="55"><input type="text" name="csr" readonly="readonly" size="3" value="2345" tabindex="2"></td>
<td>Nombre Usuario: <input type="text" name="txt" id="txt1" value="" autocomplete="off" tabindex="3"></td>
<td><input type="text" name="serie" tabindex="4"></td>
<td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
</tr>
</table>

<table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_2">
<tr>
<td>Sel</td>
<td width="36">Csr:</td>
<td width="70">Modelo:</td>
<td width="47">Serie:</td>
<td width="170">Comentarios:</td>
</tr>
<tr>
<td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
<td height="55"><input type="text" name="csr" readonly="readonly" size="3" value="2345" tabindex="2"></td>
<td>Nombre Usuario: <input type="text" name="txt" id="txt2" value="" autocomplete="off" tabindex="3"></td>
<td><input type="text" name="serie" tabindex="4"></td>
<td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="5"></textarea></td>
</tr>
</table>

<div id="contenedorOpt" class="capa" style="display:none;"></div>
</form>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #15 (permalink)  
Antiguo 20/04/2010, 15:49
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Primero que todo muxas gracias por tu paciencia Adler....

Hice algunas modificaciones para que las filas crecieran mediante el FOR que dijimos en los mensajes anteriores dejandolo asi:

Código ASP:
Ver original
  1. <form method="post" action="">
  2.  
  3.  
  4. <table width="430" height="103" border="1" align="center" bordercolor="#0000FF" id="idt_1">
  5. <tr>
  6. <td width="213"><p>Distribuidor: <%=response.write (""&DISTRIBUIDOR&"") %></p>
  7. <p>Local: <%=response.write (""&LOC&"") %></p>
  8. <p>Fecha: <%=response.write (""&ACTUAL&"") %></p></td>
  9. <td width="130"><p>Gu&iacute;a de Despacho </p><p>N&ordm;: <%=response.write (""&GUIA_D&"") %></p></td>
  10. <input type="hidden" name="csr" readonly="readonly" size="10" value="<%=distribuidor%>" ></td>
  11. <input type="hidden"  value="<%=loc%>" autocomplete="off" ></td>
  12. <input type="hidden" name="txt" id="txt1" value="<%=cuen%>" autocomplete="off">
  13. <input type="hidden" name="serie" value="<%=ACTUAL%>" ></td>
  14. <input type="hidden" value="<%=GUIA_D%>" >
  15. </table>
  16. <p align="center">&nbsp;</p>
  17. <%For cuen = ""&CSR_INI&"" To ""&rs("CONTADOR")&"" Step 1%>
  18. <table width="351" border="1" align="center" bordercolor="#0000FF" id="idt_<%=cuen%>">
  19. <tr>
  20. <td>Sel</td>
  21. <td width="36">Csr:</td>
  22. <td width="70">Modelo:</td>
  23. <td width="47">Serie:</td>
  24. <td width="170">Comentarios:</td>
  25. </tr>
  26. <tr>
  27. <td width="21"><input type="checkbox" name="cod" value="" tabindex="1" ></td>
  28. <td height="55"><input type="text" name="csr" readonly="readonly" size="2" value=<%=cuen%> tabindex="3"></td>
  29. <td><input type="text" name="txt"  id="txt<%=cuen%>" value="" autocomplete="off" tabindex="4"></td>
  30. <td><input type="text" name="serie" tabindex="5"></td>
  31. <td><textarea name="comentarios" cols="30" rows="3" wrap="VIRTUAL" tabindex="6"></textarea></td>
  32. </tr>
  33. </table>
  34. <%next%>
  35. <div id="contenedorOpt" class="capa" style="display:none;"></div>
  36. </form>

Lo del código Ajax lo dejé intacto porque no lo domino muxo.....jejejeje



Aps....para recibir los parámetros debo hacerlo mediante un FOR cierto??
Creo que debo hacerlo asi pero no estoy seguro:

Código ASP:
Ver original
  1. <%
  2. csr=Request("csr")
  3. txt =Request("txt")
  4. serie =Request("serie")
  5. comentarios =Request("comentarios")
  6.  
  7. set Cnn = Server.CreateObject("ADODB.Connection")
  8. set rs = Server.CreateObject ("ADODB.Recordset")
  9. Cnn.Open Session("cnx")
  10.  
  11. vecCSR = split ( csr ,",")
  12. vecTXT = split ( txt ,",")
  13. vecSERIE = split ( serie ,",")  
  14. vecCOMENTARIOS = split ( comentarios ,",")  
  15. for i=0 to UBound(vecCSR)
  16.  
  17. strSQL =" INSERT INTO KARDEX_HISTORIAL_REP (Nro_CSR, MODELO, Nro_serie,  COMENTARIO) VALUES
  18. (' "&trim(vecCSR(i))&" ',' "&trim(vecTXT(i))&" ', ' "&trim(vecSERIE(i))&" ', ' "&trim(vecCOMENTARIOS(i))&" ') "
  19. set rs = Cnn.Execute(strSQL)
  20. next

No se si estaré en lo correcto pero el valor de los modelos con lo del autocompletar llegarían como txt1, txt2, txt3 y asi sucesivamente cierto??

Entonces como debería hacerlo para recibir los parámetros y hacer el INSERT???

De antemano muchas gracias por responder mis dudas Adler......
  #16 (permalink)  
Antiguo 23/04/2010, 07:11
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Podría algo como esto

Código ASP:
Ver original
  1. Dim Arr()
  2. cantCampos = 0
  3. For each campo in Request.Form
  4. if Request.Form(campo) <> "" then
  5. cantCampos = cantCampos +1
  6. Redim preserve Arr(cantCampos)
  7. Arr(cantCampos) = Request.Form(campo)
  8. end if
  9. Next
  10.  
  11. Dim Arr2()
  12. Dim Arr3()
  13.  
  14. j = 0
  15. for i = 1 to ubound(Arr) step 2
  16. Redim preserve Arr2(j)
  17. Arr2(j) = Arr(i)
  18. j = j +1
  19. next
  20.  
  21. x = 0
  22. for i = 2 to ubound(Arr) step 2
  23. Redim preserve Arr3(x)
  24. Arr3(x) = Arr(i)
  25. x = x +1
  26. next
  27.  
  28. for i = 0 to 1
  29. Response.Write Arr2(i) & ","
  30. Response.Write Arr3(i) & "<br />"
  31. next

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #17 (permalink)  
Antiguo 23/04/2010, 08:24
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Gracias por la respuesta Adler.....pero cómo hago para utilizarlos en el insert????
porque me llegan todos los campos pero "desordenados".......


En un response.write me aparece:

Cita:

TOTUS, 90800, 90801, 90802, ALAMEDA , HE-1000, ADVANCED 1190 GL BL, PV2000N,23-04-2010, 123, 456, 789
En este caso Totus y Alameda son como identifico al proveedor, y están en medio de los campos de los productos...esto son los datos de los productos:


Csr Modelo Serie
90800 HE-1000 123
90801 ADVANCED 1190 GL BL 456
90802 PV2000N 789


¿Cómo los separo para insertar los datos?

De antemano muchas gracias
  #18 (permalink)  
Antiguo 23/04/2010, 11:57
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Cita:
En este caso Totus y Alameda son como identifico al proveedor, y están en medio de los campos de los productos...esto son los datos de los productos:
Esto no me dice nada.

Si lo que quieres es recibir los valores de 4 cuatros campos (Csr, txt, Serie y comentarios), lo puedes hacer así. También ha cada campo campo has de darle el nombre a todos los campos

Cita:
Dim Arr() ' Valores de todos los campos recibidos
cantCampos = 0 ' cantidad de campos recibidos
For each campo in Request.Form
if Request.Form(campo) <> "" then
cantCampos = cantCampos +1
Redim preserve Arr(cantCampos)
Arr(cantCampos) = Request.Form(campo)
end if
Next

Dim Arr2() ' Valores del primer campo de cada tr
Dim Arr3() ' Valores del segundo campo de cada tr
Dim Arr4() ' Valores del tercer campo de cada tr
Dim Arr5() ' Valores del cuarto campo de cada tr

j = 0
for i = 1 to ubound(Arr) step 4
Redim preserve Arr2(j)
Arr2(j) = Arr(i)
j = j +1
next

x = 0
for i = 2 to ubound(Arr) step 4
Redim preserve Arr3(x)
Arr3(x) = Arr(i)
x = x +1
next


p = 0
for i = 3 to ubound(Arr) step 4
Redim preserve Arr4(x)
Arr4(p) = Arr(i)
p = p +1
next

z = 0
for i = 4 to ubound(Arr) step 4
Redim preserve Arr5(z)
Arr5(z) = Arr(i)
z = z +1
next



for i = 0 to j-1
strSQL =" INSERT INTO KARDEX_HISTORIAL_REP (Nro_CSR, MODELO, Nro_serie, COMENTARIO) VALUES('"&trim(Arr2(i))&" ',' "&trim(Arr3(i))&" ', ' "&trim(Arr4(i))&" ', ' "&trim(Arr5(i) )&" ') "
set rs = Cnn.Execute(strSQL)
next
Por cierto estaría bien que usaras transacciones, por si hubiera algún problema con algún insert

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />

Última edición por Adler; 23/04/2010 a las 13:23 Razón: Dar mas info
  #19 (permalink)  
Antiguo 25/04/2010, 00:02
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problema con ASP y Ajax

Nuevamente gracias x la respuesta...pero me da este error:

Cita:
Tipo de error:
Error de Microsoft VBScript en tiempo de ejecución (0x800A0009)
El subíndice está fuera del intervalo: 'i'
/bodega2/valida_for.asp, línea 50
Y la linea 50 es:

Cita:
strSQL =" INSERT INTO KARDEX_HISTORIAL_REP (Nro_CSR, MODELO, Nro_serie, COMENTARIO)VALUES('"&trim(Arr2(i))&" ','"&trim(Arr3(i))&"', '"&trim(Arr4(i))&"', '"&trim(Arr5(i) )&"') "


Por lo que entiendo significa que uno de los arrays está vacío o algo asi o no??

De antemano muchas gracias
  #20 (permalink)  
Antiguo 25/04/2010, 06:07
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con ASP y Ajax

Hola

Sí, lo había hecho al vuelo
Prueba ahora

Código ASP:
Ver original
  1. <&#37;
  2. Dim Arr() ' Valores de todos los campos recibidos
  3. For each campo in Request.Form
  4. valCampos = valCampos & Request.Form(campo)
  5. Next
  6.  
  7. division = Split(valCampos, ",")
  8.  
  9. for i = 0 to UBound(division)
  10. Redim preserve Arr(i+1)
  11. Arr(i) = Trim(division(i))
  12. next
  13.  
  14. Dim Arr2() ' Valores del primer campo de cada tr
  15. Dim Arr3() ' Valores del segundo campo de cada tr
  16. Dim Arr4() ' Valores del tercer campo de cada tr
  17. Dim Arr5() ' Valores del cuarto campo de cada tr
  18.  
  19. j = 0
  20. for i = 0 to ubound(Arr)-1 step 4
  21. if Arr(i) <> "" then
  22. Redim preserve Arr2(j)
  23. Arr2(j) = Arr(i)
  24. j = j +1
  25. end if
  26. next
  27.  
  28. x = 0
  29. for i = 1 to ubound(Arr)-1 step 4
  30. if Arr(i) <> "" then
  31. Redim preserve Arr3(x)
  32. Arr3(x) = Arr(i)
  33. x = x +1
  34. end if
  35. next
  36.  
  37.  
  38. p = 0
  39. for i = 2 to ubound(Arr)-1 step 4
  40. if Arr(i) <> "" then
  41. Redim preserve Arr4(p)
  42. Arr4(p) = Arr(i)
  43. p = p +1
  44. end if
  45. next
  46.  
  47. z = 0
  48. for i = 3 to ubound(Arr)-1 step 4
  49. if Arr(i) <> "" then
  50. Redim preserve Arr5(z)
  51. Arr5(z) = Arr(i)
  52. z = z +1
  53. end if
  54. next
  55.  
  56. ' Tu conexión
  57.  
  58. for i = 0 to j-1
  59. strSQL =" INSERT INTO KARDEX_HISTORIAL_REP (Nro_CSR, MODELO, Nro_serie, COMENTARIO) VALUES('"&trim(Arr2(i))&" ',' "&trim(Arr3(i))&" ', ' "&trim(Arr4(i))&" ', ' "&trim(Arr5(i) )&" ') "
  60. Cnn.Execute(strSQL)
  61. next
  62. Cnn.Close
  63. set Cnn = nothing
  64.  
  65. Response.Write("Datos Insertados con &eacute;xito")
  66. %>

Ten en cuenta que ahora todos los campos del form han de tener el mismo nombre

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />

Etiquetas: ajax, asp
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 23:00.