Multi Calculation between Fields within a While

0

I do not know how to proceed in this. In the code below I have a loop that returns me quantity and value per line how to do this calculation dynamically by line         loop{ linha 1 <input type="text" name="qtd" > x <input type="text" name="valor" > = result linha 2 <input type="text" name="qtd" > x <input type="text" name="valor" > = result linha 3 <input type="text" name="qtd" > x <input type="text" name="valor" > = result } ....

    
asked by anonymous 29.05.2015 / 02:57

1 answer

0

So I understand, do you want a calculator?

var content = document.querySelector("#content");
for(var i=0;i<10;i++){
  (function(){
    var div = document.createElement("div");
    var input1 = document.createElement("input");
    var input2 = document.createElement("input");
    var result = document.createElement("span");
    input1.oninput=input2.oninput=function(e){
      result.innerHTML = Number(input1.value)*Number(input2.value);
    }
    div.appendChild(input1);
    div.appendChild(document.createTextNode(" x "));
    div.appendChild(input2);
    div.appendChild(document.createTextNode(" = "));
    div.appendChild(result);
    content.appendChild(div);
  })();
}
<span id="content"></span>
    
29.05.2015 / 03:18