Lo tendras que hacer con ajax aqui te dejo un ejemplo que hice con jQuery
Código PHP:
$('#cod_venta').keydown(function (event){
if(event.keyCode != 13)
return;
var _obj = $(this), tip_venta = $('#tipo_venta').val();
var venta = (tip_venta == 1) ? 'Boleta' : 'Factura';
if(_obj.val() == '')
return alert('Ingrese el codigo de la ' + venta);
$.post('index.php?Page=ListGuia&TheAction=getVenta&LocalAction=1', {
cod_venta: _obj.val(), tip_venta: tip_venta
}, function (response){
response = $.evalJSON(response);
if(response.error != 'ok')
return alert('No se hallo la ' + venta);
$('#ven_id').val(response.ven_id);
$('#cli_id').val(response.cli_id);
$('#' + (response.cli_ruc ? 'nro_factura' : 'nro_pedido')).val(response.ven_cod);
$('#cli_nom').val(response.cli_nom);
$('#cli_dir').val(response.cli_dir);
$('#cli_ruc').val(response.cli_ruc);
$('#tip_pago').val(response.ven_tip_pago);
$('#pto_llegada').val(response.cli_dir);
var tr = $('.guia-det').html('');
tr.append('<table width="97%" cellpadding="0" cellspacing="0"><tr>'
+ '<th width="18%">Codigo</th><th width="18%">Unidad</th><th width="16%">Cantidad</th>'
+ '<th width="48%">Descripción</th></tr></table>');
var tabla = $('.guia-det table:first');
$(response.ven_det).each(function (i, elem){
tabla.append('<tr align="center"><td>' + elem.cod + '</td><td>' + elem.unid
+ '</td><td>' + elem.cant + '</td><td>' + elem.desc + '</td></tr>');
});
$('#peso_aprox').attr('disabled', false);
$('.guia-det').show();
});
});