0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="estilos.css" rel="stylesheet">
<title>Documento sin título</title>
                    <h1 id="titulo">
                        Proyecto final
                    </h1>

</head>

<body>

        <script>

    function sum() {
        var primer_numero = document.getElementById('txt1').value;
        var segundo_numero = document.getElementById('txt2').value;
        var result = parseInt(primer_numero) * parseInt(segundo_numero);
        var itbs = result *0.18;


        if (!isNaN(result) && !isNaN(itbs) ){
             document.getElementById('txt3').value = result;
             document.getElementById('txt4').value = itbs;
        }
    }

function obtenerdatos(){
    var nom_p = document.getElementById('txt0').value;
    var cant = document.getElementById('txt1').value;
    var precio = document.getElementById('txt2').value;
    var resultado = document.getElementById('txt3').value;
    var itbs = document.getElementById('txt4').value;

    document.mi_formulario.nom_producto.value = nom_p;
    document.mi_formulario.can_obtenida.value = cant;
    document.mi_formulario.precio.value = precio;
    document.mi_formulario.resultado.value = resultado;
    document.mi_formulario.itbs.value = itbs;
}

        </script>

<section>
    <form name="mi_formulario" id="mi:formulario" method="get" autocomplete="on">

<input type="text" id="txt0" placeholder="Nombre del producto" autofocus="autofocus"/>
    <input type="text" id="txt1" placeholder="Cantidad" autofocus="autofocus"/>
    <input type="text" id="txt2" placeholder="Precio" autofocus="autofocus" />
    <input type="text" id="txt3" onkeyup="sum();" placeholder="Resultado" autofocus="autofocus"/>
    <input type="text" id="txt4" onkeyup="sum();" placeholder="itbs" autofocus="autofocus"/>
    <input type="button" name="btn1" value="Agregar" onclick="obtenerdatos()" id="boton" autofocus="autofocus">




    <table border="1" id="tabla">
    <tr>
        <td><input type="text" name="nom_producto" id="nom_producto"  id="nom"</td> 
        <td><input type="text" name="can_obtenida" id="can_obtenida" id="can"</td>
        <td><input type="text" name="precio" id="precio" id="precio"</td>   
        <td><input type="text" name="resultado" id="resultado" id="resul"</td>
        <td><input type="text" name="itbs" id="itbs" id="itbs" </td>

    </tr>
    <tr>
 <!--       <td><input type="text" name="nom_producto" id="nom_producto"  id="nom"</td> 
        <td><input type="text" name="can_obtenida" id="can_obtenida" id="can"</td>
        <td><input type="text" name="precio" id="precio" id="precio"</td>   
        <td><input type="text" name="resultado" id="resultado" id="resul"</td>
        <td><input type="text" name="itbs" id="itbs" id="itbs" </td>
-->
    </tr>
    </table>

    <table>
    <tr>

    </tr>
    </table>

    </form>

</section>  
    <h1 id="nom_p">Nom. Producto</h1>
    <h1 id="can">Cantidad</h1>
    <h1 id="pre">Precio</h1>
    <h1 id="resul">Resultado</h1>
    <h1 id="itbs">ITBS</h1>

<script>
</script>



</body>
</html>

1 respuesta 1

1

Para agregar más td a tu tabla puedes usar esta forma.

 $("#tabla").append(`tus td que desees agregar`);
    //
    $("#txt1").val('');
    $("#txt2").val('');

Pero si quieres sumar lo que tiene tus inputs de la tabla te recomendaria usar arreglos :

var datatemp = [];
funcion agregar(){
  datatemp.push({
      "id":id,
      "producto":producto
    });

generarTabla();
}

function generarTabla(){
 for(int i =0 ;i < datatemp.length ; i++){
    $("#tabla").append(`tus td que desees agregar`);
  }
}
1
  • Gracias por tu tiempo para responder, para la proxima añado la explicacion.
    – jarol
    el 2 abr. 2019 a las 4:17

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.