Decidí crear una utilidad web que ayudará a las personas a realizar conversiones fáciles de grados a Farenheit. Cada elemento html en la página se muestra como se esperaba, el único problema es el javascript...
Metodología
Utilicé javascript onkeydown() para registrar el método que responderá a las pulsaciones del teclado en el campo de entrada de grados. Esta función llama a otra función llamada update() que se supone que obtiene la entrada que el usuario ingresó en el campo de grados, la procesa y muestra el resultado en el campo farenheit. Excepto que parece haber un problema en la función de actualización. No sé si es así como estoy accediendo a las propiedades de los campos de entrada y asignando... por favor ayuda
Código
<!DOCTYPE html> <html> <head> <title>Degrees to Farenheit Converter </title> <!--add dependencies--> <link rel="stylesheet" href="materialize/css/materialize.min.css"/> <link rel="stylesheet" href="mystyle.css"/> </head> <body> <div class="container"> <center><h5>Convert Degrees to Farenheit</h5></center> <center><h5>Temp in Degrees:</h5><input class="form-control"type="number" id="degrees" onkeydown="update()"/><br/></center> <center><h5>Temp in Celsius</h5><input class="form-control"type="number" id="farenheit"/></center> </div> </body> <script type="text/javascript"> let degree=document.getElementbyId("degrees"); let far=document.getElementById("farenheit"); //iplement a function that will listen on text //change inside the farenheit field function update(){ //alert("a key was pressed"); //get the number and convert to farenheit let temp=parseInt(degree.value); //convert to farenheit and display in th other //boex let faren=1.8*temp+32; //display the result in the celsius field far.value=faren; } </script> </html>Javascript distingue entre mayúsculas y minúsculas, y usted escribe document.getElementbyId() cuando el correcto es document.getElementById()
let degree = document.getElementById("degrees"); let far= document.getElementById("farenheit"); //iplement a function that will listen on text //change inside the farenheit field function update(){ //alert("a key was pressed"); //get the number and convert to farenheit let temp=parseInt(degree.value); //convert to farenheit and display in th other //boex let faren=1.8*temp+32; //display the result in the celsius field far.value=faren; } <div class="container"> <center><h5>Convert Degrees to Farenheit</h5></center> <center><h5>Temp in Degrees:</h5><input class="form-control"type="number" id="degrees" onkeyup="update()"/><br/></center> <center><h5>Temp in Celsius</h5><input class="form-control"type="number" id="farenheit"/></center> </div>