In: Computer Science
Create a very simple temperature converter form having two text fields. The first one is where the user will enter temperature. The second field is where the computed temperature value is displayed depending on the unit (F or C).use html and javascript
Answer
Here i am converting temperature in celsius to fahrenheit. Here is the html and javascript code to do the task
tempc.html
<html>
<title>Temperature Converter</title>
<head>
</head>
<body>
<!-- Ask user for input in celsius , and pass the value to function, and write the result in second input field -->
<label for="temp">temperature in celcious </label><br><input type="text" name="temp" id="a"><br>
<label for="b">converted celcious into farenheit</label><br> <input type="text" name="far" id="b"><br>
<button onclick="tempConverter(document.getElementById('a').value)">Convert</button>
<script>
function tempConverter(temp)
{
var inputC = document.getElementById("b");
inputC.value=(temp*(9/5))+32;
//temperature conversion
}
</script>
</body>
</html>
output
The celsius can be converted into faranheit by using following equation.
Any doubt in the html script comment please
Thanks in advance