Converter temperatures in HTML. Urgent help

0

I must do a program in html with javascript components that do the following: Enter a temperature in degrees Celsius and with a button convert the temperature in Farenheit and in Kelvin to two different fields. It only turns me to farenheit, to kelvin no, I did not do the button because I do not know how, if you could help me I'm very grateful

This is my code:

  

<html>
<title>Conversor Celsius a Farenheit/Kelvin</title>
<body>

<h2>Conversor de temperaturas</h2>
<p>Escriba aqui el valor de la temperatura en celcius:</p>

<p>
  <label>Celsius</label>
  <input id="inputCelsius" type="number" placeholder="Celsius" oninput="CelsiusFarenheit(this.value)" onchange="CelsiusFarenheit(this.value)">
</p>
<p>Farenheit: <span id="Farenheit"></span></p>
<p>Kelvin: <span id="Kelvin"></span></p>

<script>
function CelsiusFarenheit(temp) {
  document.getElementById("Farenheit").innerHTML=((temp*9/5)+32);
}
function CelsiusKelvin(temp2) {
  document.getElementById("Kelvin").innerHTML=(temp2+273);
}
</script>
</body>
</html>
    
asked by Manu Longo 14.11.2018 в 01:23
source

1 answer

0

I think without the button it is very difficult to do what you want. With a serious button like this:

<html>
<title>Conversor Celsius a Farenheit/Kelvin</title>
<body>

<h2>Conversor de temperaturas</h2>
<p>Escriba aqui el valor de la temperatura en celcius:</p>

<p>
  <label>Celsius</label>
  <input id="inputCelsius" type="number" placeholder="Celsius">
  <button onclick="CelsiusKelvin()">Calcular</button>
</p>
<p>Farenheit: <span id="Farenheit"></span></p>
<p>Kelvin: <span id="Kelvin"></span></p>

<script>
function CelsiusKelvin() {
  var temp = document.getElementById("inputCelsius").value;
  document.getElementById("Farenheit").innerHTML=((temp*9/5)+32);
  document.getElementById("Kelvin").innerHTML=(parseInt(temp)+273);
}
</script>
</body>
</html>
    
answered by 14.11.2018 в 01:31