English

# Length Calculator or Unit Conversion in javascript

This is a Length calculator or unit conversion script, which converts any of the entered unit(inches, feet, centimeter, kilometer, mile) to all other units including inches(in), feet(ft), centimeter(cm), kilometer(km), mile(mile).

# Features

• The javascript function will help you to calculate or convert inches(in) to feet(ft),centimeter(cm), kilometer(km),mile and vice versa.
• If you change the value for particular unit, conversion is automatically done for all other units.
• The value is rounded to two decimal point.
• Just copy the code in to your page and use it.

# Preview

Length calculator or Unit Conversion script

 Length calculator H inch cm feet kilo Mile

Javascript Code

<!-- Script by hscripts.com -->
<script type="text/javascript">
function checnum(as)
{
var dd = as.value;

if(isNaN(dd))
{
dd = dd.substring(0,(dd.length-1));
as.value = dd;
}
} function inchconv(val){
with(document.conv){
cm.value = (Math.round(inch.value*2.54)).toFixed(2);
feet.value=(Math.round(inch.value/12)).toFixed(2);
var tmp=(inch.value* 2.54)*Math.pow(10,-5);
kilo.value=((inch.value* 2.54)*Math.pow(10,-5)).toFixed(2);
miles.value=((inch.value*1.58)*Math.pow(10,-5)).toFixed(2);
} }
function feetconv(val){
with(document.conv){
cm.value=(Math.round(feet.value*30.48)).toFixed(2);
inch.value=(Math.round(feet.value*12)).toFixed(2);
kilo.value=((feet.value* 3.05)*Math.pow(10,-4)).toFixed(2);
miles.value==((feet.value*1.8900000000000001)*Math.pow(10,-4)).toFixed(2);
} } function cmconv(val){
with(document.conv){
feet.value = (Math.round(cm.value/30.84)).toFixed(2);
inch.value = (Math.round(cm.value/2.54)).toFixed(2);
kilo.value=((cm.value*1)*Math.pow(10,-5)).toFixed(2);
miles.value==((cm.value*6.21)*Math.pow(10,-6)).toFixed(2);
} } function kiloconv(val){
with(document.conv){
feet.value = ((kilo.value*3.28)*Math.pow(10,3)).toFixed(2);
inch.value = ((kilo.value*3.94)*Math.pow(10,4)).toFixed(2);
cm.value=((kilo.value*1)*Math.pow(10,5)).toFixed(2);
miles.value=((kilo.value* 0.621)).toFixed(2);
} } function milesconv(val){
with(document.conv){
feet.value =((miles.value* 5.28)*Math.pow(10,3)).toFixed(2);
inch.value = ((miles.value*6.34)*Math.pow(10,4)).toFixed(2);
cm.value=((miles.value*1.61)*Math.pow(10,5)).toFixed(2);
kilo.value=((miles.value*1.61)).toFixed(2);
} } </script>
<!-- Script by hscripts.com -->

HTML CODE
<form name=conv>
<table style='border:green solid 1px;font-size:12px'width=220 height=50>
<tr>
<td>Length calculator</td>
<td align=right><a style='font-size:13px; text-decoration:none; color:#3D366F;cursor:pointer' href='https://www.hscripts.com'>H</a></td></tr>
<tr><td align=center><input onkeyUp="checnum(this);inchconv();" value=1 name=inch></td><td>inch</td></tr>
<tr><td align=center><input
onkeyUp="checnum(this);cmconv();" value=2.25 name=cm
></td><td>cm</td></tr>
<tr><td align=center><input onkeyUp="checnum(this);feetconv();" value=0 name=feet
></td><td>feet</td></tr>
<tr><td align=center><input onkeyUp="checnum(this);kiloconv();" value=0 name=kilo ></td><td>kilo</td></tr>
<tr><td align=center><input onkeyUp="checnum(this);milesconv();" value=0 name=miles></td><td>Miles</td></tr>
</table> </form> <br>

• Release Date - 07-04-2008
• For customization of this script or any script development, mail to support@hscripts.com

# Usage

• He we have explained with a form
• Creating the form using following HTML code
• ```<form name=conv><table><tr><td></td></tr>
<tr><td>
<input onkeyUp="checnum(this);inchconv();"name=inch>inch
</td></tr>
<tr><td >
<input onkeyUp="checnum(this);cmconv();" name=cm >cm
</td></tr>
<tr><td >
<input onkeyUp="checnum(this);feetconv();" name=feet >feet
</td></tr>
<tr><td >
<input onkeyUp="checnum(this);kiloconv();" name=kilo >kilo
</td></tr>
<tr><td >
<input onkeyUp="checnum(this);milesconv();" name=miles>Mile
</td></tr>
</form></table>```
• The javascript function inchconv(), cmconv(), feetconv(), kiloconv(), milesconv() is triggered and Length or Unit conversion is done when key is released in the appropriate field.