# Convert temperatures between Fahrenheit, Celcius, and Kelvin

Page 1 of 1

## 1 Replies - 1799 Views - Last Post: 14 December 2010 - 05:42 AM

### #1 spearfish

• Monkey in Training

Reputation: 10
• Posts: 746
• Joined: 10-March 08

# Convert temperatures between Fahrenheit, Celcius, and Kelvin

Posted 02 April 2008 - 10:15 AM

Description: You will need a Javascript containing function "convert" in the head of the document.

The name of the form and input fields must remain as they are, or else you will need to change the script.

Please PM my Dream.In.Code account with any questions which I will respond to via comments on this post.

This has been tested.
-SpearThis will instantly convert a temperature on one scale into it's equivalents on the other scales, using an onchange handler.

It's formatted into an HTML document currently, rip out the parts and place them were you want in your own page.
```<html>
<script type="text/javascript">
function convert(known) {
if (known == "Cel") {
var cel = document.theform.cel.value;
var far = (cel * 1.8) + 32;
far = Math.round(far * 1000) / 1000;
var kel = cel + 273;
kel = Math.round(kel * 1000) / 1000;
document.theform.far.value = far;
document.theform.kel.value = kel;
} else if (known == "Far") {
var far = document.theform.far.value;
var cel = (far - 32) / 1.8;
cel = Math.round(cel * 1000) / 1000;
var kel = cel + 273
kel = Math.round(kel * 1000) / 1000;
document.theform.cel.value = cel;
document.theform.kel.value = kel;
} else if (known == "Kel") {
var kel = document.theform.kel.value;
var cel = kel - 273;
cel = Math.round(cel * 1000) / 1000;
var far = (cel * 1.8) + 32;
far = Math.round(far * 1000) / 1000;
document.theform.cel.value = cel;
document.theform.far.value = far;
}
}
</script>
<body>
<form name='theform'>
<p><b>Fahrenheit:</b> <input type='text' name='far' onchange="convert('Far')" /></p>
<p><b>Celcius:</b> <input type='text' name='cel' onchange="convert('Cel')" /></p>
<p><b>Kelvin:</b> <input type='text' name='kel' onchange="convert('Kel')" /></p>
</form>
</body>
</html>

```

Is This A Good Question/Topic? 0

## Replies To: Convert temperatures between Fahrenheit, Celcius, and Kelvin

### #2 workneh

Reputation: 0
• Posts: 0
• Joined: 14-December 10

## Re: Convert temperatures between Fahrenheit, Celcius, and Kelvin

Posted 14 December 2010 - 05:42 AM