There are two inputs, I want to enter numbers there and in the third get the result of the division. Where is the mistake? The result is not displayed.

function calc1() { var gold1, dps1, res1 gold1 = parseInt(document.getElementById("gold1").value); dps1 = parseInt(document.getElementById("dps1").value); res1 = gold1*dps1; document.getElementById("res1").value = res1; } 
 <input id="gold1" placeholder="gold" onkeyup="calc1()"> <input id="dps1" placeholder="dps" onkeyup="calc1()"> <input id="res1" onkeyup="calc1()"> 

  • So, why the key release event on the input to which you are going to record the result? - Igor
  • The result of the multiplication is displayed remarkably - vp_arth
  • Clearly, someone corrected the issue to the working condition, now it is useless - vp_arth

2 answers 2

Correct

document.getElementById ("res1"). innerHTML = res1;

on

 document.getElementById("res1").value = res1; 

and it will work

  • I changed the question in the snippet does not work ... - Tarasovych
  • one
    @Tarasovych and who will call your function, Pushkin? Add <button type="button" onclick="calc1()">Click</button> - Igor
  • @Igor thanks. And how to make the value appear without pressing the button? - Tarasovych
  • one
    @Tarasovych <input onkeyup="calc1()" ... - Igor
  • 2
    @Tarasovych add onkeyup="calc1()" to both fields for input, then enterter will not have to be pressed and if one of the fields is not filled in - the third will output NaN (Not-a-Number) - Nikita Gordeyev

The answer from NikitaGordeev

 <input id="gold1" placeholder="gold" onkeyup="calc1()"> <input id="dps1" placeholder="dps" onkeyup="calc1()"> <input id="res1" onkeyup="calc1()">