I'm creating a small calculator that converts Kilograms to Pounds
and Pounds in Kilograms .
My goal is to insert a value into a first input
and display the result in a second input
that follows. For example:
<input id='in' value='1' type='text'/> <!-- O usuário insere 1KG no primeiro input para converter em Pounds -->
<input id='out' value='2.20462262' type='text'/> <!-- E o resultado aparecerá aqui no seguindo input: 2.20462262 -->
The basic concept is this! But now I wanted to have a Google Translate button in the middle of these two inputs
, in which I would reverse the calculation units, ie at the beginning we would be calculating - ( KG para Pounds
), clicking on the button will invert the units of calculation / weight and now we will be calculating - (% with%). All this in one button.
Better explaining. At first we would be calculating how many kilos would be a Pounds para KG
value in Pounds:
.caixa {display: inline-block;}
<div class="caixa">
Quilogramas<br />
<input id='field1' value='50' type='text'/>
</div>
<div class="caixa"><button id='switch'>Inverter Unidade</button></div>
<div class="caixa">
Pounds<br />
<input id='field2' value='110.23' type='text'/>
</div>
By clicking the X
button, it reverses the weight units and can now calculate how many Inverter Unidade
will be Pounds
in X
:
.caixa {display: inline-block;}
<div class="caixa">
Pounds<br />
<input id='field1' value='100' type='text'/>
</div>
<div class="caixa"><button id='switch'>Inverter Unidade</button></div>
<div class="caixa">
Quilogramas<br />
<input id='field2' value='45.35' type='text'/>
</div>
Have you understood what I want to do? Here is the code for what I have so far:
function calcPD(){
var pound = document.getElementById("field1").value;
var calc = quilos / 2.2046;
var resul = document.getElementById("field2").value=calcular.toFixed(2);
}
function calcKg(){
var kg = document.getElementById("field1").value;
var calc = quilo * 2.2046;
var resul = document.getElementById("field2").value=calcular.toFixed(2);
}