»
EnglishFrenchVietnamese

Print - Temperature Conversion Script - JavaScriptBank.com

Full version: jsB@nk » Calculation » Equivalent » Temperature Conversion Script
URL: https://www.javascriptbank.com/temperature-conversion-script.html

Temperature Conversion Script © JavaScriptBank.comThis script converts temperature to/from Celcius, Fahrenheit, Kelvin, and Rankin. Enter a number in the first text box, select unit to convert from, select unit to convert to, then press the 'Convert' button. The answer will appear in the last text box.

Full version: jsB@nk » Calculation » Equivalent » Temperature Conversion Script
URL: https://www.javascriptbank.com/temperature-conversion-script.html



CSS
<style type="text/css">body{background-color:white;padding:5 40 0 40;font-family:verdana;font-size:9pt;color:black;}td{font-size:8pt;font-family:verdana;}</style><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script language="javascript">// TEMPERATURE CONVERSION SCRIPT - V 1.0// AUTHOR: Brian Gosselinfunction convertTemp(){var d=document.forms["tempConvert"];var inp=d.intemp.value;if((inp!='')&&(!isNaN(inp))&&(inp!=Number.POSITIVE_INFINITY)&&(inp!=Number.NEGATIVE_INFINITY)){inp=eval(inp);switch(d.fromU.selectedIndex){case 0: //C->Kinp=inp+273.15; break;case 1: //F->Kinp=(inp+459.67)/1.8; break;case 2: //R->Kinp=inp/1.8; break;}switch(d.toU.selectedIndex){case 0: //K->Cinp=inp-273.15; break;case 1: //K->Finp=(inp*1.8)-459.67; break;case 2: //K->Rinp=inp*1.8; break;}d.outtemp.value=(Math.round(inp*100)/100); //CHANGE THE 2nd NUMBER FOR MORE OR LESS ACCURACY}else d.outtemp.value='(Invalid input)';}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="tempConvert"><table cellpadding="0" cellspacing="0" border=1 bgcolor="#EEDCBE"><tr><td><table cellpadding="10" cellspacing="0" border="0"><tr valign="bottom" align="center"><td>Enter<br>temperature<br><br><input type="text" name="intemp" size="11" value=0></td><td>Select temperature<br>to convert <i>from</i>.<br><br><select name="fromU"><option>° Celcius</option><option>° Fahrenheit</option><option>° Rankin</option><option>Kelvin</option></select></td><td><input type="button" value=" Convert ->" onclick="convertTemp()"></td><td>Select temperature<br>to convert <i>to</i>.<br><br><select name="toU"><option>° Celcius</option><option>° Fahrenheit</option><option>° Rankin</option><option>Kelvin</option></select></td><td>Answer:<br><br><br><input type="text" name="outtemp" size="11"></td></tr><tr align="center"><td colspan="5"><input type="reset" value="  Reset  "></td></tr></table></td></tr></table></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->