The textbox doesn’t get the value of the function. Can you help? Thanks.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<p id="demo2"></p>
<input type = "textbox" id = "text">
<script>
function toCelcius(f) {
return (5/9) * (f-32);
}
function toFahrenheit(c) {
return (9/5) * c + 32;
}
document.getElementById("demo").innerHTML = toCelcius(451);
document.getElementById("demo2").innerHTML = toFahrenheit(0);
document.getElementById("text").Value = toFahrenheit(0);
</script>
</body>
</html>
Javascript is case sensitive.You are using "Value" instead of "value" to assign the calculated value to textbox.
document.getElementById("text").Value = toFahrenheit(0);
Change above code to
document.getElementById("text").value = toFahrenheit(0);
Complete Updated Code
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <!DOCTYPE html> <html> <body> <p id="demo"></p> <p id="demo2"></p> <input type = "textbox" id = "text"> <script> function toCelcius(f) { return (5/9) * (f-32); } function toFahrenheit(c) { return (9/5) * c + 32; } document.getElementById("demo").innerHTML = toCelcius(451); document.getElementById("demo2").innerHTML = toFahrenheit(0); document.getElementById("text").value = toFahrenheit(0); </script> </body> </html> </body> </html>
Thanks A2H.
davelewicki
Thanks A2H.
Glad to be of help