How can I show the product name when I insert product code?

0

Purchase products, when inserting code, show the name of the product to which it belongs.

This is the code:

<div class="md-modal md-dark custom-width md-effect-9" id="formnproducto">
  <div class="md-content">
    <div class="modal-header">
      <h3>Compra de Producto</h3>
      <button type="button" class="close md-close" data-dismiss="modal" aria-hidden="true">&times;</button>
    </div>
    <div class="modal-body form">
      
      <form id='fcproducto' name='fcproducto' data-parsley-validate>

       <div class="form-group" id='mproducto' style="display:none">
          <label>Producto</label>
          <select class="form-control" id="producto">
            <option value='0' selected>Seleccionar</option> 
            
          </select>
        </div>
        
      <div class="form-group" id='mcodigo'>
        <label>Código</label> <input type="text" class="form-control" required placeholder="Código" id='codigo' name='codigo' autofocus>
      </div>
      
      
      <div id="clicboton"><span id="btnbuscar" class="btn" onclick="$('#btncancelar').show('slow'); $('#btnbuscar').hide('slow'); $('#mproducto').show('slow'); $('#mcodigo').hide('slow');">Buscar</span><span style="display:none" id="btncancelar" class="btn" onclick="$('#btnbuscar').show('slow'); $('#btncancelar').hide('slow'); $('#mcodigo').show('slow'); $('#mproducto').hide('slow');">Regresar</span></div>

      <div class="form-group">
        <label>Nombre</label> <input type="text" class="form-control" id='nombre' name='nombre' onchange="document.getElementById('').innerHTML = valorname = this.value">
      </div>

      <div class="form-group">
        <label>Cantidad</label> <input type="text" class="form-control" required placeholder="Cantidad" id='cantidad' name='cantidad' value="1">
      </div>
      <div class="form-group">
        <label for="cant" class="control-label">Nota</label> <textarea class="form-control" required placeholder="Nota" id='nota' name='nota' rows="3"></textarea>
      </div>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default btn-flat md-close" data-dismiss="modal">Cancelar</button>
      <button type="submit" class="btn btn-primary btn-flat">Aceptar</button>
    </div>
  </div>
</div>

Screenshot:

    
asked by Cheke Sanchez 28.03.2017 в 18:09
source

2 answers

1

Something like that would be your called AJAX :

<script type='text/javascript'>
    $('#clicboton').on('click',buscaNombre);
    function buscaNombre(){
        $.get('url',
            {
                codigo:$('#codigo').value
            },
            function (data,textStatus,xhr){
                $('#nombre').value(data.nombre);
            }
        );
    }
</script>
    
answered by 28.03.2017 в 18:31
0

If you use a call ajax() you can send the written code to a function php where you can search by code the product and return the name of the product.

Example:

// obtenemos el codigo insertado preferentemente colocar un id al input código
var _codigo= $('#mcodigo').val();

$.ajax({
            type: 'post',
            data: 'buscarcodigo?codigo='+_codigo,
            dataType: 'html',
            success: function(data){
            $('#nombre').val(data.valor);// colocamos el nombre al campo requerido

      }
});
    
answered by 28.03.2017 в 18:39