Converting meter to feet and vice versa

Both the units ( meter and feet ) are used as unit of length or height or distance in any type of measurement. We can develop one JavaScript application to convert any input to feet or in meter.

1 foot = 0.3048 meters
1 meter = 3.2808399 feet

Here is the demo

Output here

When it is to be converted to feet then it is assumed that input is meter. Same way when it is converted to meter then it is assumed that entered data is in feet. Note the above conversion formulas.

So we only have to multiply the entered value by the respective conversion constant. As we will be using one input box to enter the numeric value, we will be using two buttons one for converting to meeter to feet and other one for converting feet to meter. JavaScript code is here

<title>Javascript Form Validation</title>
<script language='JavaScript' type='text/JavaScript'>
function validate(type) {
	alert('Fill the Input box before submitting');
	return false;
var res=3.2808*document.form1.textinput.value;
var unit=" feet";
var res=0.3048*document.form1.textinput.value;
var unit=" meter";

document.getElementById("result").innerHTML=res.toFixed(2) + unit;
return false;
<form name='form1' action='' method='post' 
	onSubmit='return validate();'>
Input :<input type=text name=textinput size=10>
<input type=button value='Convert to Feet' onClick=validate('to_feet');>
<input type=button value='Convert to Meter' onClick=validate('to_meter');>

<div id=result></div>

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 All rights reserved worldwide Privacy Policy Disclaimer