-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarenheit.html
More file actions
39 lines (34 loc) · 1.11 KB
/
farenheit.html
File metadata and controls
39 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<html>
<head>
<script>
//find celsius from fahrenheit javascript function
//by tutorialsmade.com
function findCelsius(){
var fahrenheit = document.getElementById("Fahrenheit").value;
var celsius;
if(fahrenheit != ''){
celsius = (fahrenheit - 32) * 5/9;
document.getElementById("output").innerHTML = celsius;
}else{
document.getElementById("output").innerHTML = "Please enter a value!";
}
}
//this is just to make sure if the user enter number or not, not actually needed for this program
//this function will allow only numbers to be entered in the textbox
function allowOnlyNumbers(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
</script>
</head>
<body>
<h2>Enter Fahrenheit</h2>
<input type="text" id="Fahrenheit" onkeypress="return allowOnlyNumbers()" />
<strong>Fahrenheit</strong>
<h4>Output: <span id="output"></span></h4>
</body>
</html>