Full version: jsB@nk » Calculation » Length Converter script
URL: https://www.javascriptbank.com/length-converter-script.html
Use this practical script to easily convert between the 7 most popular length units- centimeters, meters, kilometers, miles, inches, feet and yards. Simply enter a number, and let the script display the desired equivalents. Cool.
Full version: jsB@nk » Calculation » Length Converter script
URL: https://www.javascriptbank.com/length-converter-script.html
<script type="text/javascript">// Length Converter script- By Bruce Zhangvar factors1 = new Array(1, 0.01, 0.00001, 0.00000621, 0.3937, 0.0328, 0.01094);var factors2 = new Array(100, 1, 0.001, 0.000621, 39.37, 3.28, 1.094);var factors3 = new Array(100000, 1000, 1, 0.621, 39370, 3280, 1094);var factors4 = new Array(160934, 1609.34, 1.60934, 1, 63360, 5280,1760);var factors5 = new Array(2.54, 0.0254, 0.0000254, 0.0000158, 1, 0.08333, 0.02778);var factors6 = new Array(30.48, 0.3048, 0.0003048, 0.0001896, 12, 1, 0.3333);var factors7 = new Array(91.44, 0.9144, 0.0009144, 0.0005688, 36, 3, 1);var factors = new Array(factors1,factors2,factors3,factors4,factors5,factors6,factors7);function convert_unit(){from_index = document.length_con.from_unit.selectedIndex;to_index = document.length_con.to_unit.selectedIndex;factor = factors[from_index][to_index];document.getElementById("formula").innerHTML = document.length_con.from_unit.options[document.length_con.from_unit.selectedIndex].text + " = " + factor + " " + document.length_con.to_unit.options[document.length_con.to_unit.selectedIndex].text;if(isNaN(document.length_con.from_value.value))document.getElementById("to_value").innerHTML = "Not a valid number.";elsedocument.getElementById("to_value").innerHTML = factor * document.length_con.from_value.value;}</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<form name="length_con"><table><tr><td>From </td><td><select name=from_unit onChange="convert_unit()";><option> centimeters<option> meters<option> kilometers<option> miles<option> inches<option> feet<option> yards</select></td><td> To </td><td><select name=to_unit onChange="convert_unit()";><option> centimeters<option> meters<option> kilometers<option> miles<option> inches<option> feet<option> yards</select></td></tr><tr><td> </td><td colspan="3"><div id="formula">centimeters = 1 centimeters</div></td></tr><tr><td colspan="4"> </td></tr><tr><td>Enter </td><td><input type="text" name="from_value" value="1" size="12" maxlength="12"></td><td> <input type=button value="To" onClick="convert_unit()";> </td><td><div id="to_value">1</div></td></tr></table></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->