Length Calculator or Unit Conversion in javascript
About
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
a) The javascript function will help you to calculate or convert inches(in) to feet(ft),centimeter(cm), kilometer(km),mile and vice versa.
b) If you change the value for particular unit, conversion is automatically done for all other units.
c) The value is rounded to two decimal point.
d) Just copy the code in to your page and use it.
Preview
Length calculator or Unit Conversion script
Code
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 -->
For customization of this script or any script development, contact us at support@hscripts.com
Usage
Here we have explained with a form
a) 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><br>
b) 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.
c) Just copy the javascript code and use it for free.
License
- The javascript (misspelled as java script) is given under GPL License
- i.e. Free use for those who use the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.