Mon Sep 12, 2011 9:34 pm
<html>
<title>temperature transformer</title>
<body>
<script language="JavaScript" type="text/javascript">
function converttemperature(temperature, typeScale){
var Celsius, Kelvin, Fahrenheit;
switch (typeScale){
case "F":
Fahrenheit = temperature;
if (temperature){
Celsius = ((5/9) * (temperature-32));
Kelvin = ((5/9)*(temperature-32) + 273)
}else{
Celsius = "";
Kelvin = "";
}
Kelvin = Kelvin.toFixed(2)
Celsius = Celsius.toFixed(2)
break;
case "K":
Kelvin = temperature;
if (temperature){
Celsius = Kelvin - 273;
Fahrenheit = ((Celsius * 9/5) + 32)
}else{
Fahrenheit = '';
Kelvin = '';
}
Fahrenheit = Fahrenheit.toFixed(2)
Celsius = Celsius.toFixed(2)
break;
case "C":
Celsius = temperature;
if (temperature){
Fahrenheit = ((temperature * 9/5) + 32)
Kelvin = ((5/9)*(Fahrenheit-32) + 273)
}else{
Fahrenheit = '';
Kelvin = '';
}
Kelvin = Kelvin.toFixed(2)
Fahrenheit = Fahrenheit.toFixed(2)
break;
}
document.getElementById("kelvinValue").value = Kelvin
document.getElementById("celsiusValue").value = Celsius
document.getElementById("fahrenheitValue").value = Fahrenheit
}
</script>
<form name="temperature_input">
Celsius: <input type="text" id="celsiusValue" name="celsius" style=" width: 50px;"
onkeyup="converttemperature(this.value, 'C')">
<br>
Fahrenheit: <input type="text" id="fahrenheitValue" name="fahrenheit" style=" width: 50px;"
onkeyup="converttemperature(this.value, 'F')" onchange="converttemperature(this.value, 'F')" >
<br>
Kelvin: <input type="text" id="kelvinValue" name="kelvin" style=" width: 50px;"
onkeyup="converttemperature(this.value, 'K')">
</form>
</body>
</html>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.