Total members 11895 |It is currently Sun Dec 22, 2024 10:21 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : temperature transformer between different types
 TEMPERATURE AND HEAT CONTROL Assembly     -  
 Types of Registers     -  
 Types of Pointers in C++     -  
 pointers to derived types     -  
 assembler directives types     -  
 java data types     -  
 What are the types of jdbc drivers.?     -  
 Get Registered File Types and Their Associated Icons in C#     -  
 lesson9: XSD Complex Types Indicators     -  
 MYSQL TEXT field types lengths     -  



Topic Tags

JavaScript Functions






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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