There are 2 forms that recalculate values from one to another:
The first form counts the quantity of the product and in the second form shows the price for this product.
The second form when entering the price shows how much product you can buy in the 1st form
I want to make a function that will determine the id of the input tag in html (or something that could determine the difference between these forms), and depending on this, the function should choose which formula to use and where to get the value for the calculation, and what form to show the result ( 1st or 2nd).
Help reduce the code, because now you have to enter the same values twice to recalculate the same.
Perhaps there is some other approach?
<input id="real" type="number" name="real" oninput="showValue();"> <input id="game" type="number" name="game" oninput="showValue();">
function showValue(price) { id = '?';//Как найти id?? if (id == 'game') document.getElementById("real").value = Math.floor(document.getElementById("game").value / price); else if (id == 'real') document.getElementById("game").value = Math.round(document.getElementById("real").value * price); }