How to pass the VALUE of an INPUT to another INPUT of a table created with JQuery?

3

You see, I have my code, in which of a search that I do, when selecting the result the fields (INPUTS) are filled automatically using the autocomplete. Now, clicking on add using JQuery I have created a table which creates all the INPUTS similar to the one that receives all the information above. What I want to do is to click on 'Add' the INPUT that is filled with the Autocomplete is empty and that information goes to the INPUT created with Jquery, but I have no idea how to do it.

This is my code:

$(document).ready(function() {
    $("#masfilas").click(function(){
        $("#mytable").append('<tr><td><input type="text" id="qty" name="quantity" size="5" title="Cantidad"/></td><td><input type="text" id="upc" name="codigo" size="12" title="Código"/></td><td><input type="text" id="nomprod" name="nombre" size="23" title="Nombre"/></td><td><input type="text" id="precio" name="price" size="10" title="Precio del producto"/></td><td><input type="text" id="discount" name="discount" size="15" title="Descuento"/></td><td><input type="text" id="impuestos" class="imp" name="impuestoivi" size="15" title="Impuesto de Ventas"/></td><td><input type="text" id="total" class="imp" name="totalizar" size="15" title="Total de Línea"/></td><td><a href="#" class="delete" title="Eliminar línea">ELIMINAR</a></td></tr>');
        $('.delete').off().click(function(e) {
            $(this).parent('td').parent('tr').remove();
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="70%" align="center">
	<tr bgcolor="#CCCCCC">
    	<td width="70%" align="left" colspan="2"><b>DETALLE</b></td>
    </tr>
    <tr>
    	<td width="70%"><input type="text" name="itemsearch" id="item" size="50" placeholder="INICIAR BÚSQUEDA" title="Ingrese Nombre del Articulo" /></td>
    </tr>
</table>

<table width="70%" align="center">
	<tr>
    	<td colspan="9"><b>Agregar Artículos / Servicios:</b></td>
    </tr>
    <tr>
    	<td>Cantidad:</td>
        <td>Código:</td>
        <td>Nombre:</td>
        <td>Precio:</td>
        <td>Descuento (%):</td>
        <td>Impuesto:</td>
        <td>Total:</td>
        <td colspan="2">Opciones:</td>
    </tr>
    <tr>
    	<td><input type="text" id="qty" name="quantity" size="5" title="Cantidad"/></td>
        <td><input type="text" id="upc" name="codigo" size="12" title="Código" placeholder="744105300000" readonly="readonly"/></td>
        <td><input type="text" id="nomprod" name="nombre" size="23" title="Nombre" readonly="readonly"/></td>
        <td><input type="text" id="precio" name="price" size="10" title="Precio del producto" placeholder="CRC. 0.00"/></td>
        <td><input type="text" id="discount" name="discount" size="15" title="Descuento" placeholder="0.00%"/></td>
        <td><input type="text" id="impuestos" class="imp" name="impuestoivi" size="15" title="Impuesto de Ventas" placeholder="CRC. 0.00"/></td>
        <td><input type="text" id="total" class="imp" name="totalizar" size="15" title="Total de Línea" placeholder="CRC. 0.00"/></td>
        <td><a href="#" title="Agregar línea" id="masfilas" class="add_form_field">AGREGAR</a></td>
        <td><a href="#" title="Eliminar línea">ELIMINAR</a></td>
    </tr>
</table>

<table width="70%" align="center" border="1" id="mytable" class="table-bordered table-striped">
	<tr bgcolor="#CCCCCC">
    	<td width="70%" align="left" colspan="8"><b>RESUMEN DEL CARRITO</b></td>
    </tr>
    <tr>
    	<td width="3%">Cantidad:</td>
        <td width="10%">Código:</td>
        <td width="13%">Nombre:</td>
        <td width="5%">Precio:</td>
        <td width="9%">Descuento (%):</td>
        <td width="10%">Impuesto:</td>
        <td width="10%">Total:</td>
        <td colspan="2" width="10%">Opciones:</td>
    </tr>
</table>

For your attention and help, thank you!

    
asked by Diego_Esquivel 18.05.2018 в 23:43
source

1 answer

1

Instead of using inputs, you can use simple text. I leave an example with the first input, you can do the same with all others.

$(document).ready(function() {
    $("#masfilas").click(function(){
        var qty = $("#qty");
        $("#mytable").append('<tr><td>' + qty.val() + '</td><td><input type="text" id="upc" name="codigo" size="12" title="Código"/></td><td><input type="text" id="nomprod" name="nombre" size="23" title="Nombre"/></td><td><input type="text" id="precio" name="price" size="10" title="Precio del producto"/></td><td><input type="text" id="discount" name="discount" size="15" title="Descuento"/></td><td><input type="text" id="impuestos" class="imp" name="impuestoivi" size="15" title="Impuesto de Ventas"/></td><td><input type="text" id="total" class="imp" name="totalizar" size="15" title="Total de Línea"/></td><td><a href="#" class="delete" title="Eliminar línea">ELIMINAR</a></td></tr>');
        $('.delete').off().click(function(e) {
            $(this).parent('td').parent('tr').remove();
        });
        qty.val("");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="70%" align="center">
	<tr bgcolor="#CCCCCC">
    	<td width="70%" align="left" colspan="2"><b>DETALLE</b></td>
    </tr>
    <tr>
    	<td width="70%"><input type="text" name="itemsearch" id="item" size="50" placeholder="INICIAR BÚSQUEDA" title="Ingrese Nombre del Articulo" /></td>
    </tr>
</table>

<table width="70%" align="center">
	<tr>
    	<td colspan="9"><b>Agregar Artículos / Servicios:</b></td>
    </tr>
    <tr>
    	<td>Cantidad:</td>
        <td>Código:</td>
        <td>Nombre:</td>
        <td>Precio:</td>
        <td>Descuento (%):</td>
        <td>Impuesto:</td>
        <td>Total:</td>
        <td colspan="2">Opciones:</td>
    </tr>
    <tr>
    	<td><input type="text" id="qty" name="quantity" size="5" title="Cantidad"/></td>
        <td><input type="text" id="upc" name="codigo" size="12" title="Código" placeholder="744105300000" readonly="readonly"/></td>
        <td><input type="text" id="nomprod" name="nombre" size="23" title="Nombre" readonly="readonly"/></td>
        <td><input type="text" id="precio" name="price" size="10" title="Precio del producto" placeholder="CRC. 0.00"/></td>
        <td><input type="text" id="discount" name="discount" size="15" title="Descuento" placeholder="0.00%"/></td>
        <td><input type="text" id="impuestos" class="imp" name="impuestoivi" size="15" title="Impuesto de Ventas" placeholder="CRC. 0.00"/></td>
        <td><input type="text" id="total" class="imp" name="totalizar" size="15" title="Total de Línea" placeholder="CRC. 0.00"/></td>
        <td><a href="#" title="Agregar línea" id="masfilas" class="add_form_field">AGREGAR</a></td>
        <td><a href="#" title="Eliminar línea">ELIMINAR</a></td>
    </tr>
</table>

<table width="70%" align="center" border="1" id="mytable" class="table-bordered table-striped">
	<tr bgcolor="#CCCCCC">
    	<td width="70%" align="left" colspan="8"><b>RESUMEN DEL CARRITO</b></td>
    </tr>
    <tr>
    	<td width="3%">Cantidad:</td>
        <td width="10%">Código:</td>
        <td width="13%">Nombre:</td>
        <td width="5%">Precio:</td>
        <td width="9%">Descuento (%):</td>
        <td width="10%">Impuesto:</td>
        <td width="10%">Total:</td>
        <td colspan="2" width="10%">Opciones:</td>
    </tr>
</table>
    
answered by 18.05.2018 / 23:54
source