Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
Impresión del resultado de una conversión a un cuadro de texto en JavaScript y HTML

Así que estoy tratando de aprender algo de JavaScript y actualmente quiero imprimir un valor de la entrada del usuario y luego imprimirlo en un cuadro de texto que tengo.

En la consola funciona pero no imprime nada en mi interfaz gráfica de usuario.

código

 function converter() { result = document.getElementById("converted"); var to_convert = document.getElementById("to_convert").value; var unit = document.getElementById("unit").value; var converted = 0; //Fahrenheit till celsius if (unit = "F") { var converted = 1.8 / to_convert; } // Cup till liter if (unit = "cup") { var converted = 0.236 * to_convert; } //lb till kg if (unit = "lb") { var converted = 0.454 * to_convert; } result.textContent.value = converted; console.log(converted); // (F - 32) / 1.8 = Celsius // cup * 0.236 = liter // lb * 0.454 = kg }
 <form> <fieldset> <input type="text" id="to_convert" value="" size="5" /><br/> <select id="unit"> <option value="F">Fahrenheit to Celcius</option> <option value="cup">cup to liters</option> <option value="lb">lb/pound to kg</option> </select> <input onclick="converter()" value="Konvertera" type="button" /> <input type="text" id="converted" value="[resultat här]" size="15" /> </fieldset> </form>

código

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

¡Esto está mal! : result.textContent.value = converted
El correcto es: result.value = converted

 function converter() { result = document.getElementById("converted"); var to_convert = document.getElementById("to_convert").value; var unit = document.getElementById("unit").value; var converted = 0; //Fahrenheit till celsius if (unit = "F") { var converted = 1.8 / to_convert; } // Cup till liter if (unit = "cup") { var converted = 0.236 * to_convert; } //lb till kg if (unit = "lb") { var converted = 0.454 * to_convert; } result.value = converted; console.log(converted); // (F - 32) / 1.8 = Celsius // cup * 0.236 = liter // lb * 0.454 = kg }
 <form> <fieldset> <input type="text" id="to_convert" value="" size="5" /><br/> <select id="unit"> <option value="F">Fahrenheit to Celcius</option> <option value="cup">cup to liters</option> <option value="lb">lb/pound to kg</option> </select> <input onclick="converter()" value="Konvertera" type="button" /> <input type="text" id="converted" value="[resultat här]" size="15" /> </fieldset> </form>

about 4 years ago · Juan Pablo Isaza Relatório

0

Debe asignarlo así: result.value = converted

 result.value = converted
about 4 years ago · Juan Pablo Isaza Relatório

0

Debe reemplazar result.textContent.value = converted por result.value = converted

 result.value = converted;

Y funcionará bien.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda