I want to be able to clone the table with the functions cargar_precio
and operacion
. When writing a name in the input ITEM
show me in the input VALOR_RE_MO
the price of said ITEM
, The script clones correctly, and serve the functions but only for the first row or table, I was reviewing Some responses from the community but do not resemble this situation, I also tried to go through the nodes until the next input
but it did not work.
SCRIPT to clone table
$(function(){
// Clona la fila oculta que tiene los campos base, y la agrega al final de
la tabla
$("#adicional").on('click', function(){
$("#tabla tbody tr:eq(0)").clone().removeClass('fila-
fija').appendTo("#tabla");
});
// Evento que selecciona la fila y la elimina
$(document).on("click",".eliminar",function(){
var parent = $(this).parents().get(0);
$(parent).remove();
});
});
SCRIPT to show prices
function cargar_precio(valor) {
var codigo = '';
switch(valor){
case '':
codigo = '';
break;
case 'ANCOL':
codigo = '100';
break;
case 'ARTEL':
codigo = '200';
break;
}
$('#VALOR_RE_MO').val(codigo);
}
function operacion() {
cargar_precio($('#ITEM').val().toUpperCase());
var valor = parseInt( $('#VALOR_RE_MO').val()),
cantidad = parseInt( $('#CANTIDAD').val() );
if(!isNaN( valor ) && !isNaN( cantidad )){
$('#VALOR_RE_MO').val( valor * cantidad );
}
}
HTML
<table id="tabla">
<label>Item</label>
<td><input type="text" name="ITEM" id='ITEM'
onkeyup='cargar_precio(this.toUpperCase());' autofocus="autofocus">
</td>
<label>Cantidad</label>
<td><input type="text" name="CANTIDAD" id='CANTIDAD'
onkeyup="operacion(this);"
/></td>
<label>Valor</label>
<td><input type="text" name="VALOR_RE_MO" id='VALOR_RE_MO'/></td>
</table>