Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/10/2012, 09:36
nataliagb1992
 
Fecha de Ingreso: septiembre-2012
Ubicación: Sevilla
Mensajes: 144
Antigüedad: 11 años, 7 meses
Puntos: 0
Añadir elementos de un campod e texto a un textarea

Lo que necesit hacer es algo tipo al programa de los supermercads en los que se pasa un codigo de barras y al pulsar intro se añade en un textarea. Pues bien llev uno o dos dias intentandolo y no me sale n hay frm s dej qui lo que tengo y aver si me pdeis ayudar :

formulario
Código HTML:
Ver original
  1.         <div id="formularioArt">
  2.             <form action="entradaArticulos2.php" method="post" id="formu">
  3.                 <legend>Entrada Almacén por Lotes</legend>
  4.                 <br/>
  5.                 <label>Código de Barras: </label>
  6.                 <input name="cBar" id="cBar" type="text" size="20" maxlenght="200" autofocus/>
  7.                 <br/>
  8.                 <label>Fecha Ingreso: </label>
  9.                 <input type="text" id="fechaFactura" name="fechaFactura" maxlenght="5" required/>
  10.                 <script>
  11.                     $(function() {
  12.                         $( "#fechaFactura" ).datepicker({
  13.                             showOtherMonths: true,
  14.                             selectOtherMonths: true,
  15.                             dateFormat:'dd/mm/yy',
  16.                             firstday:1
  17.                         });  
  18.                         $('#fecha').datepicker($.datepicker.regional['es']);                                  
  19.                     });
  20.                 </script>
  21.                 <br/><br/>
  22.                 <script>
  23.                     $(document).ready(function(){
  24.                         $('#cBar').keydown(function(event){
  25.                             if (event.which == 13){
  26.                                 $.ajax({
  27.                                     url: 'lotes.php',
  28.                                     type: 'POST',
  29.                                     data: 'cBar=' + $(this).val(),
  30.                                     success: function(data){
  31.                                         $('#productos tbody').html(data);
  32.                                     }
  33.                                 });
  34.                                 event.preventDefault();
  35.                                 //buscar_productos();
  36.                             }
  37.                         });
  38.                     });
  39.                     /*  function ajax(cBar){
  40.    $.post("ajax.php",{cBarras:cBar},function(respuesta){
  41.         jQuery("#resultado").html(respuesta);
  42.     });
  43.     }*/  
  44.                     /* $(document).ready(function(){
  45.                         $('#cBar').keypress(function(event){
  46.                             if(event.which == 13){
  47.                                 buscar_productos();
  48.                             }
  49.                             event.preventDefault();
  50.                         });
  51.                     });*/
  52.                     /*function buscar_productos(){//el error me lo da aqui
  53.                         $.ajax({
  54.                             type: 'POST',
  55.                             url: 'lotes.php',
  56.                             data: {
  57.                                 code: $('#cBar').val()
  58.                             },
  59.                             success: function(data){
  60.                                 $('#productos tbody').append(data);
  61.                             }
  62.                         });
  63.                     }*/
  64.                 </script>
  65.                 <table id="productos" >
  66.                     <thead>
  67.                         <tr>
  68.                             <td>Código</td>
  69.                            
  70.                         </tr>
  71.                     </thead>
  72.                     <tbody>
  73.  
  74.                     </tbody>
  75.                 </table>
  76.                 <input id="aceptar" name="aceptar" type="submit" value="Aceptar"/>
  77.             </form>
  78.         </div>
  79.  
  80.     </body>
  81. </html>

busco los codde barras para mstrarls

Código PHP:
Ver original
  1. header("Content-Type: text/html;charset=utf-8");
  2. include_once 'clases/Class_Bd.php';
  3. echo " <link rel='stylesheet' type='text/css' media='screen' href='cssPageGrid.css' />";
  4. $conexion = new Conecta_DB;
  5. $conexion->conectar();
  6. $res = $_POST['cBar'];
  7. echo 'res :' . $res;
  8. $consulta = "SELECT cBarras FROM altaArticulos WHERE cBarras='$res' limit 1";
  9. echo 'consulta'.$consulta;
  10. $query = $conexion->consultar($consulta);
  11. if ($query) {
  12.     foreach ($query as $row) {
  13.         echo '<tr>';
  14.         echo '<td><input type="hidden" name="codigo[]" value="' . $row['cBarras'] . '"/>' . $row['cBarras'] . '</td>';
  15.         echo '</tr>';
  16.     }
  17. }/* elseif (empty($res)) {
  18.     echo "Debe intruducir algún código de barras registrado . $conexion->msgError ";
  19. } else {
  20.     echo "Lo sentimos el artículo que usted intenta introducir no está registrado . $conexion->msgError ";
  21. }*/
  22. ?>

y ay otra pagina la cual funciona bien para agregarls a la base de dats