Tuesday, September 30, 2014

Centimeter To Feet Converter in JavaScript

This program that I wrote in JavaScript will convert the height of the person from centimeter to feet. I'm using HTML as my markup language and JavaScript to perform as series of computation and conversion of values from centimeter to feet. I hope you will find my work useful in your programming projects and assignments using JavaScript.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

Thank you very much.


Sample Output of Our Program

Program Listing

<HTML>
<TITLE> Height Converter </TITLE>
<BODY BGCOLOR="lightgreen">
<font face="comic sans ms" size=5>
<TABLE cellSpacing=0 cellPadding=0 width=250 border=0>
<H3>  Height Converter </center> </H3>
<FORM name=cminch>
        <TBODY>
        <TR>
          <TD>
            <FONT face="comic sans ms"><INPUT 
            onblur=cmconvert() value=2.54 name=cm> CM</FONT></TD>
        </TR>
        <TR>
          <TD>
            <FONT face="comic sans ms"><INPUT 
            onblur=feetconvert() value=0 name=feet> </FONT>FEET </TD>
        </TR>
        <TR>
          <TD>
            <FONT face="comic sans ms"><INPUT 
            onblur=inchconvert() value=1 name=inch> </FONT>INCHES</TD>
        </TR>
        <TR>
          <TD width="50%">
              <p align="center"><input type="button" value="Submit" name="B3"></p>
          </TD>
        </TR></TBODY></FORM></TABLE>
      <p align="left">
      <FONT face="Comic Sans Ms" size="3">Note: 1 Inch = 2.54 cm, 1 Feet = 30.48 cm, 1 
      Feet = 12 Inch</FONT>
      <BR>

<SCRIPT language=JavaScript>


function roundit(which){
return Math.round(which*100)/100
}

function cmconvert(){
with (document.cminch){
feet.value = roundit(cm.value/30.84);
inch.value = roundit(cm.value/2.54);
}
}

function inchconvert(){
with (document.cminch){
cm.value = roundit(inch.value*2.54);
feet.value=roundit(inch.value/12);
}
}

function feetconvert(){
with (document.cminch){
cm.value=roundit(feet.value*30.48);
inch.value=roundit(feet.value*12);
}
}

</SCRIPT>
</font>
</body>

DOWNLOAD FILE HERE

No comments:

Post a Comment