Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/03/2013, 12:59
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Me hace el autocompletado sólo en la primera fila.

Hola, he hecho un autocompletado en un código. En dicho código agrego filas en un div donde tengo un input llamado recambio que es donde hago el autocompletado. Pero sólo me hace el autocompletado en la primera fila. Y cuando agrego mas filas ya no lo hace.

funcion agregar filas:
Código Javascript:
Ver original
  1. function agregar() {
  2.    
  3.    var contLin = 3;
  4.    var tr, td, tabla;
  5.  
  6.    tabla = document.getElementById('tabla');
  7.    tr = tabla.insertRow(tabla.rows.length);
  8.    td = tr.insertCell(tr.cells.length);
  9.    td.innerHTML = "<input name='button' type=button onclick='agregar()' value='+' >";
  10.    td = tr.insertCell(tr.cells.length);
  11.    td.innerHTML = "<input name='button' type=button onclick='borrarUltima()' value='-' >";
  12.    td = tr.insertCell(tr.cells.length);
  13.    td.innerHTML = "<input type='text' value='' size='5' >";
  14.    td = tr.insertCell(tr.cells.length);
  15.    td.innerHTML = "<input type='text' name='recambio' id='recambio' size='10' >";
  16.    td = tr.insertCell(tr.cells.length);
  17.    td.innerHTML = "<input type='text' value='' size='25' >";
  18.    td = tr.insertCell(tr.cells.length);
  19.    td.innerHTML = "<input type='text' value='' size='5' >";
  20.    td = tr.insertCell(tr.cells.length);
  21.    td.innerHTML = "<input type='text' value='' size='5' >";
  22.    td = tr.insertCell(tr.cells.length);
  23.    td.innerHTML = "<input type='text' value='' size='5' >";
  24.    td = tr.insertCell(tr.cells.length);
  25.    td.innerHTML = "<input type='text' value='' size='5' >";
  26.    td = tr.insertCell(tr.cells.length);
  27.    td.innerHTML = "<img src='imagenes_menu/untitled.png' width='20' height='20' style='cursor:pointer' />";
  28.    contLin++;
  29. }
  30.  
  31. function borrarUltima() {
  32.    ultima = document.all.tabla.rows.length - 1;
  33.    if(ultima > -1){
  34.       document.all.tabla.deleteRow(ultima);
  35.       contLin--;
  36.    }
  37. }
  38.    </script>

El autocompletado:

Código Javascript:
Ver original
  1. <?php
  2. include("conexion_autocompletado.php");//se incluyen los datos para realizar la conexion a su base de datos
  3. $con2 ="SELECT recambio
  4. FROM  almacen000"; //consulta para seleccionar las palabras a buscar, esto va  a depender de su base de datos//consulta para seleccionar las palabras a  buscar, esto va a depender de su base de datos
  5. $query = mysql_query($con2);
  6. ?>
  7. <script>
  8.    $(function() {
  9.      
  10.       <?php
  11.      
  12.       while($row= mysql_fetch_array($query)) {//se reciben los valores y se almacenan en un arreglo
  13.      
  14.      $elementos[]= '"'.$row['recambio'].'"';
  15.    
  16. }
  17. $arreglo= implode(", ", $elementos);
  18. //junta los valores del array en una sola cadena de texto
  19.  
  20.       ?>  
  21.      
  22.       var availableTags=new Array(<?php echo $arreglo; ?>);//imprime el arreglo dentro de un array de javascript
  23.            
  24.       $( "#recambio").autocomplete({
  25.          minLength: 2,
  26.          source: availableTags
  27.       });
  28.      
  29.    
  30.     $(document).keypress(function(e){
  31.                 switch(e.which)
  32.                 {
  33.                     case 13:  nuevo_cliente(); ///// Enter /////
  34.                              break;
  35.                 }
  36.             });  
  37.      
  38.    });  
  39.    
  40. var popup = null;
  41.       function nuevo_cliente(recambio)
  42.       {
  43.          // Si el popup ya existe lo cerramos
  44.          if(popup!=null)
  45.             popup.close();
  46.  
  47.          // Capturamos las dimensiones de la pantalla para centrar el popup
  48.          altoPantalla = parseInt(screen.availHeight);
  49.          anchoPantalla = parseInt(screen.availWidth);
  50.          
  51.          // Calculamos el centro de la pantalla
  52.          centroAncho = parseInt((anchoPantalla/2))
  53.          centroAlto = parseInt((altoPantalla/2))
  54.    
  55.          // dimensiones del popup
  56.          anchoPopup = 500;
  57.          altoPopup = 200;
  58.  
  59.          // Calculamos las coordenadas de colocación del Popup
  60.          laXPopup = centroAncho - parseInt((anchoPopup/2))
  61.          laYPopup = centroAlto - parseInt((altoPopup/2))
  62.          
  63.          
  64.             var recambio = $('#recambio') .val();
  65.    
  66.    
  67.          // Definimos que página vamos a ver
  68.          pagina = "buscar_recambio.php?id=" +recambio;
  69.          
  70.          popup  = window.open(pagina,"Imagenes","scrollbars=yes,status=no,width=" +  anchoPopup + ", height=" + altoPopup + ",left = " + laXPopup + ",top = "  + laYPopup);
  71.    
  72. }
  73. </script>


El div donde agrego las filas:

Código HTML:
Ver original
  1. <div class="albaran">
  2. <table id="tabla">
  3. <tr class="cab_factura">
  4.      <td class="enlace10"></td>
  5.     <td class="enlace10"></td>
  6.     <td class="enlace10">Almacén</td>
  7.     <td class="enlace10">Referencia</td>
  8.     <td class="enlace10">Descripción</td>
  9.     <td class="enlace10">Cantidad</td>
  10.     <td class="enlace10">Precio</td>
  11.     <td class="enlace10">%Dto.</td>
  12.     <td class="enlace10">Total</td>
  13.     <td class="enlace10"></td>
  14.   </tr>
  15.  
  16. <tr>
  17.    <td><input name="button" type=button onclick="agregar();" value="+"  /></td>
  18.    <td><input name="button" type=button onclick="borrarUltima();" value="-"/></td>
  19.     <td ><input name="almacen" type="text" size="5"  /></td>
  20.     <td><input name="recambio" id="recambio" type="text" size="10"/></td>
  21.     <td><input name="descripcion" type="text" size="25"  /></td>
  22.     <td><input name="cantidad" type="text" size="5"  /></td>
  23.     <td><input name="precio" type="text" size="5"  /></td>
  24.     <td><input name="descuento" type="text" size="5"  /></td>
  25.     <td><input name="total" type="text" size="5" /></td>
  26.      <td><img src="imagenes_menu/untitled.png"  onclick="nuevo_cliente();" width="20" height="20" style="cursor:pointer"  /></td>
  27.   </tr>
  28. </div>

Gracias y un saludo