Total members 10262 | Gratitudes |It is currently Wed May 23, 2012 8:30 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: temperature transformer between different types
PostPosted: Mon Sep 12, 2011 9:34 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

temperature transformer between Celsius,Kelvin,Fahrenheit

Code:

<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>

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 What are the types of jdbc drivers.?
 lesson9: XSD Complex Types Indicators
 java data types
 Types of Pointers in C++
 Get Registered File Types and Their Associated Icons in C#

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team