Multi Field Calculation within a While

Asked

Viewed 70 times

0

I don’t know how to proceed in this. In the code below I have a loop that returns me quantity and value per line how to make this calculation dynamically per 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 }....

  • I couldn’t understand either the question or the code. I could go into more detail, please?

  • Imagine a table with 5 or more lines.... each row has 2 unit fields and value I wanted to do this calculation dynamically per line so line '1' I would put the amount in the field and would multiply by the value contained in field 2

1 answer

0

From what I understand, 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>

  • Correct.... that even more would be in several lines

  • How many exactly?

  • each row with a calculator of this

  • How many lines? user-defined?

  • there is no way to estimate line numbers because these lines would be inside a loop coming from a query in mysql

  • well, then when you return the query in mysql just put there in for....

  • Okay that’s right... just don’t know how to pass a variable to field 2

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.