How to take the otido value in a function and put in a text, Javascript?

Asked

Viewed 94 times

1

I can show in Alert but qnd I will put in text (temp2), will not!

    function mostrarValor(){
         var escalaEntrada = getRadioValor('escalaEntrada');
         var escalaSaida = getRadioValor('escalaSaida');
         var valor = parseInt(document.getElementById("temp1").value);
    if (escalaEntrada === "celsius" && escalaSaida === "kelvin") {  
            resul = (valor + 273);
            window.alert(resul);
            /*var saida = document.getElementById("temp2");
            saida.innerHTML = resultado;*/

        }
     }
  • Make sure the HTML element #temp2 exists? can also publish the relevant HTML in the question sff

  • @Miguel, yes it exists, I created it: <input id="temp2" class="temp" type="text"/>

  • Haa. I get it, it’s a little misunderstanding. The input (self closing tag) doesn’t take with text, what you want to do is modify the value. Do so: document.getElementById("temp2").value = resul;

  • That’s why it’s important to publish everything relevant and can help solve the problem :P

  • @Miguel Nossa, thanks. Thank you so much! And sorry, I’m new here rsrs.

  • No problem. I’m glad you solved

Show 1 more comment

1 answer

0

The elements input have not innerHTML since they are self closing (self enclosed).

You must use the property .value to change its value.

  • Very obg for the help ;)

Browser other questions tagged

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