*}
codea teams

Temperature Conversions



Temperature conversion functions.

Absolute Zero = -273.15 degrees celcius (zero kelvin)

Temperature Conversion Calculator
Enter a number


The following code segments are used above in the calculator.

jQuery

$(document).ready(function() { 
   $("#btngo").click(function(e) {
        if ($("#conversion_type").val() == '1') {
            ft = parseFloat($("#temp").val());
            ct = (ft - 32) * (5.0 / 9.0);
            kt = ct + 273;
            myhtml = "Farenheit: "+ft.toFixed(2)+"<br>"+"Celcius: "+ct.toFixed(2)+
                                          "<br>"+"Kelvin: "+kt.toFixed(2)+"<br>";
            $("#results").html(myhtml);
        }
        else if ($("#conversion_type").val() == '2') {
            ct = parseFloat($("#temp").val());
            ft = (ct * 9.0 / 5.0) + 32;
            kt = ct + 273;
            myhtml = "Farenheit: "+ft.toFixed(2)+"<br>"+"Celcius: "+ct.toFixed(2)+
                                          "<br>"+"Kelvin: "+kt.toFixed(2)+"<br>";
            $("#results").html(myhtml);
        }
        else if ($("#conversion_type").val() == '3') {
            kt = parseFloat($("#temp").val());
            ct = kt - 273;
            ft = (ct * 9.0 / 5.0) + 32;
            myhtml = "Farenheit: "+ft.toFixed(2)+"<br>"+"Celcius: "+ct.toFixed(2)+
                                          "<br>"+"Kelvin: "+kt.toFixed(2)+"<br>";
            $("#results").html(myhtml);
        }
   });
});

The HTML

<div style='border:1px solid #cccccc;width:400px;'>
    <table width='100%'>
        <tr><td>Enter a number</td>
            <td><input type='text' value='32' id='temp' style='width:60px;'></td>
            <td><select name='conversion' id='conversion_type'>
                <option value='1'>Farenheit</option>
                <option value='2'>Celcius</option>
                <option value='3'>Kelvin</option>
                </select>
            <td><input type='button' id='btngo' name='btngo' value='Calculate'></tr>
    </table>

</div>
<div id='results'></div>