Necesito agregar un producto que al dar clic en el botón de añadir de la tabla productos y pasar ese producto a la tabla de ventas para seguir añadiendo mas productos, pero el problema es que no puedo agregarlos, probe con input pero solo se agrega uno en en la tabla no se agrega. ayuda porfavor una sugerencia
<!--tabla de venta en donde debera añadirse los productos-->
<div class="form-group col-lg-3 col-md-3 col-sm-6 col-xs-12">
<a data-toggle="modal" id="btnAgregarProd">
<button type="button" class="btn btn-primary"><span class="fa fa-plus" data-toggle="modal"></span>Agregar producto</button>
</a>
</div>
<div class="form-group col-lg-12 col-md-12 col-xs-12">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table id="detalles" class="table table-striped table-bordered table-condensed table-hover">
<thead class="text-center" style="background-color:#A9D0F5">
<th>Opciones</th>
<th>Cod. producto</th>
<th>Producto</th>
<th>Cantidad</th>
<th>Precio Venta</th>
<th>Subtotal</th>
</thead>
<tbody>
</tbody>
<tfoot>
<th>TOTAL</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th><h4 id="total">$ 0.00</h4></th>
</tfoot>
<tbody>
</tbody>
</table>
</div>
<!--<input type="text" id="codigo">
<input type="text" id="nombre">
<input type="text" id="descripcion">
<input type="text" id="nomDesc">
<input type="text" id="pvp">-->
</div>
</div>
</div>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
<button class="btn btn-primary" type="button" id="btnGudardar" onclick="btnGuardar()"><i class="fa fa-save"></i> Guardar</button>
<button class="btn btn-danger" type="button" id="btnCancelar" onclick="btnCancel()"><i class="fa fa-arrow-circle-left"></i> Cancelar</button>
</div>
<!-- Este es el modal donde estan los productos para agregar a la tabla de venta-->
<div class="modal fade" id="modalProd" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
</div>
<form id="formPro">
<div class="modal-body">
<?php
$consulta = "SELECT pr.codigo, pr.nombre, pr.descripcion,
pr.precio_unitario, pr.stock
from productos pr
inner join subcategoria su on pr.id_subcategoria = su.id
inner join categoria cat on su.id_categoria = cat.id";
$resultado = $conexion->prepare($consulta);
$resultado->execute();
$data=$resultado->fetchAll(PDO::FETCH_ASSOC)
?>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table id="tablaProd" class="table table-striped table-bordered table-condensed table-hover" style="width:99%">
<thead class="text-center" style="background-color:#007EFA; color:#ffffff" >
<tr>
<th>Codigo</th>
<th>Producto</th>
<th>Descripcion</th>
<th>PVP</th>
<th>Stock</th>
<th>Opcion</th>
</tr>
</thead>
<tbody>
<?php
$cont = 1;
foreach($data as $dat2) {
?>
<tr>
<td><center><?php echo $dat2['codigo'] ?></center></td>
<td><?php echo $dat2['nombre'] ?></td>
<td><?php echo $dat2['descripcion'] ?></td>
<td>$ <?php echo $dat2['precio_unitario'] ?></td>
<td><?php echo $dat2['stock'] ?></td>
<input type="hidden" id="cod_<?php echo $cont; ?>" value="<?php echo $dat2['codigo']; ?>">
<input type="hidden" id="nombrep_<?php echo $cont; ?>" value="<?php echo $dat2['nombre'] ?>">
<input type="hidden" id="descripcion_<?php echo $cont; ?>" value="<?php echo $dat2['descripcion'] ?>">
<input type="hidden" id="nomDesc_<?php echo $cont; ?>" value="<?php echo $dat2['nombre'].' '.$dat2['descripcion'] ?>">
<input type="hidden" id="pvp_<?php echo $cont; ?>" value="<?php echo $dat2['precio_unitario']; ?>">
<td><div class='text-center'><div class='btn-group'><button type='button' class='btnAg' style='background-color:#D6D9E3; border:1.5px solid #187CEB;border-radius: 10px 100px / 120px;' onclick="agregar(document.getElementById('cod_<?php echo $cont; ?>').value,document.getElementById('nombrep_<?php echo $cont; ?>').value,document.getElementById('descripcion_<?php echo $cont; ?>').value,document.getElementById('nomDesc_<?php echo $cont; ?>').value,document.getElementById('pvp_<?php echo $cont; ?>').value)" class="boton"><span class='fa fa-plus'></span></button></div></div></td>
<script>
var cod_row = "";
function agregar(cod,nom,des,nd,pvp) {
$('#modalProd').modal('hide');
var Myelement = document.getElementById("codigo");
Myelement.value = cod;
var Myelement = document.getElementById("nombre");
Myelement.value = nom;
var Myelement = document.getElementById("descripcion");
Myelement.value = des;
var Myelement = document.getElementById("nomDesc");
Myelement.value = nd;
var Myelement = document.getElementById("pvp");
Myelement.value = pvp;
id_row = cod;
}
</script>
</tr>
<?php
$cont = $cont + 1;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Cerrar</button>
</div>
</form>
</div>
</div>
</div>

