Last active
August 29, 2015 14:16
-
-
Save bdjnk/6c4b11c388848cfbd6cd to your computer and use it in GitHub Desktop.
ScriptEd - HTML Form, JavaScript Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script> | |
function celsiusToFahrenheit(celsius) { | |
var fahrenheit = celsius * 9 / 5 + 32; | |
if ( ! celsius | isNaN(fahrenheit)) { | |
return ""; | |
} | |
return Math.round(fahrenheit); | |
} | |
function fahrenheitToCelsius(fahrenheit) { | |
var celsius = (fahrenheit - 32) * 5 / 9; | |
if ( ! fahrenheit | isNaN(celsius)) { | |
return ""; | |
} | |
return Math.round(celsius); | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
<label for="C2Fin">Celsius to Fahrenheit</label> | |
<input type="text" name="C2Fin" oninput="C2Fout.value=celsiusToFahrenheit(C2Fin.value);"> | |
<output name="C2Fout" for="C2Fin"></output> | |
<br> | |
<label for="F2Cin">Fahrenheit to Celsius</label> | |
<input type="text" name="F2Cin" oninput="F2Cout.value=fahrenheitToCelsius(F2Cin.value);"> | |
<output name="F2Cout" for="F2Cin"></output> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment