Skip to content

Instantly share code, notes, and snippets.

@bdjnk
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdjnk/6c4b11c388848cfbd6cd to your computer and use it in GitHub Desktop.
Save bdjnk/6c4b11c388848cfbd6cd to your computer and use it in GitHub Desktop.
ScriptEd - HTML Form, JavaScript Functions
<!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