Re: HTML code to convert F to C : OFF TOPIC

From: Wim Leys (wim.leys@lin.vlaanderen.be)
Date: Tue Jun 24 1997 - 10:20:40 PDT


Date: Tue, 24 Jun 1997 10:20:40 -0700
From: Wim Leys <wim.leys@lin.vlaanderen.be>
To: cp@opus.hpl.hp.com
Message-Id: <aabcdefg2449$foo@default>
Subject: Re: HTML code to convert F to C : OFF TOPIC

Hi Fabrice,

You are wellcome to use my JavaScript code in your Website.

You know you do not have to _include_ the JavaScript code in your
HTML-page.

Your page will not look like :
        <SCRIPT LANGUAGE="JavaScript">
        // implementatie : Wim Leys
        ...
        ...
                        return (parseInt(C, 10) * 1.8) + 32;
                } // function DegreesC2F(C)
        </SCRIPT>
        </HEAD>

but like this :
        <SCRIPT LANGUAGE="JavaScript" SRC=URL.js>
        </SCRIPT>
        </HEAD>

and you create a file containing eveything (but not including)
        <SCRIPT LANGUAGE="JavaScript">
                ...everything in between comes in a .js file...
        </SCRIPT>
You give the file a name ending on .js and you place its URL (including
the .js extension) in the "SRC=URL.js" attribute.

This way your pages are cleaner, and if something would be wrong with
the code, you only have to change it in one file, instead of each page
in witch you called the code.

I have added the newest version of this little Celcius to and from
Fahrenheid conversion program. The comments are mostly written in Dutch.

Kind regards
Wim Leys

--

<HTML> <HEAD> <TITLE>Convert &#176;Fahrenheid to/from &#176;Celcius</TITLE>

<SCRIPT LANGUAGE="JavaScript"> // implementatie : Wim Leys

/* rond een getal af tot op een aantal cijfers na of voor de komma // input : getal : het af te ronden getal (real) // naKomma : het aantal cijfers na de komma die getoond // moeten worden (integer) indien NaKomma < 0, // dan wordt getal afgerond tot op zoveel cijfers voor de komma. // Toepsssing naKomma < 0 : als je bv. wenst af te ronden op de // duizendtalen (naKomma == 3) // output : het afgeronde getal met naKomma cijfers na de komma (string) // neveneffect : geen // vb : afronden (333.3333, 2) == 333.33 afronden (333.335, 2) == 333.34 // afronden (333.3333, 0) == 333 afronden (333.511, 0) == 334 // afronden (333.3333, -2) == 300 afronden (363.3333, -2) == 400 // afronden (333.3333, -3) == 0 afronden (-363.3333, -3) == 0 // afronden (-333.3333, 2) == -333.33 afronden (-363.3333, -2) == -400 // datum & versie : 21/02/1997 versie 1.0 // datum & versie : 30/05/1997 versie 1.1 (in versie 1.0 enkel cijfers na de komma // afronden, nu ook cijfers voor de komma) */ function afronden(getal, naKomma) { var g = getal; var strG = ""; var len = 0;

if (getal == 0) { strG = "0" + ((naKomma > 0) ? "." : ""); for (var i = 1; i <= naKomma; i++) { strG += "0"; } return strG; } // if (getal == 0)

for (var i = 1; i <= naKomma; i++) { g *= 10; } for (var i = -1; i >= naKomma; i--) { g /= 10; } g = Math.round(g); for (var i = -1; i >= naKomma; i--) { g *= 10; } strG += g; len = strG.length; return strG.substring(0, len-naKomma) + ((naKomma > 0) ? "." : "") + strG.substring(len-naKomma, len); } // function afronden(getal, naKomma) /* converteer graden Fahreneheid naar graden Celsius // input : F : graden Fahrenheid (real) // output : het aantal graden Celsius (real) die overeenstemmen met // het opgegeven aantal graden Fahrenheid // neveneffect : geen // datum & versie : 21/02/1997 versie 1.0 */ function DegreesF2C(F, C) { return (parseInt(F,10) - 32) / 1.8; } // function DegreesF2C(F, C)

/* converteer graden Celsius naar graden Fahreneheid // input : C : graden Celsius (real) // output : het aantal graden Fahreneheid (real) die overeenstemmen met // het opgegeven aantal graden Celsius // neveneffect : geen // datum & versie : 21/02/1997 versie 1.0 */ function DegreesC2F(C) { return (parseInt(C, 10) * 1.8) + 32; } // function DegreesC2F(C) </SCRIPT> </HEAD>

<BODY> <H1>Convert &#176; F to and from &#176; C.</H1> <FORM> <TABLE> <TH ALIGN="left">Enter the temperature in &#176;F : <TD> <INPUT TYPE="text" NAME="F" SIZE=6><TD> &#176;F<TD> <INPUT TYPE="button" VALUE="Convert &#176;F to &#176;C" ONCLICK="form.F2C.value=DegreesF2C(form.F.value); form.F2C.value=afronden(form.F2C.value, 2)"><TD>

<INPUT TYPE="text" NAME="F2C" SIZE=6><TD> &#176;C<TR>

<TH ALIGN="left">Enter the temperature in &#176;C : <TD> <INPUT TYPE="text" NAME="C" SIZE=6><TD> &#176;C<TD> <INPUT TYPE="button" VALUE="Convert &#176;C to &#176;F" ONCLICK="this.form.C2F.value=DegreesC2F(this.form.C.value); this.form.C2F.value=afronden(this.form.C2F.value, 2)"><TD> <INPUT TYPE="text" NAME="C2F" SIZE=6><TD> &#176;F<TR>

<TH> <TR>

<TH><TD> <INPUT TYPE="reset" VALUE="Clear"><TD> <TR> </TABLE>

</FORM> </BODY> </HTML>



This archive was generated by hypermail 2b30 : Tue Jan 02 2001 - 17:31:05 PST