Convert From Feet to Kilometers Using JavaScript Code With HTML

Hello Friends Today, through this tutorial, I will tell you How can i Convert From Feet to Kilometers Using Javascript Code With HTML.Certainly! You can create a simple Feet to Kilometers converter using HTML and JavaScript. Here’s an example code:

feetkm.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feet to Kilometers Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}
#converter {
margin-top: 20px;
}
</style>
</head>
<body>
<h2>Feet to Kilometers Converter</h2>
<div id="converter">
<label for="feetInput">Feet:</label>
<input type="number" id="feetInput" placeholder="Enter feet" oninput="convertFeetToKilometers()">
<button onclick="convertFeetToKilometers()">Convert</button>
<p id="result"></p>
</div>
<script>
function convertFeetToKilometers() {
// Get the value from the input field
var feet = parseFloat(document.getElementById('feetInput').value);
// Check if the input is a valid number
if (!isNaN(feet)) {
// Convert feet to kilometers (1 foot = 0.0003048 kilometers)
var kilometers = feet * 0.0003048;
// Display the result
document.getElementById('result').innerHTML = feet + ' feet is equal to ' + kilometers.toFixed(4) + ' kilometers';
} else {
// If the input is not a valid number, display an error message
document.getElementById('result').innerHTML = 'Please enter a valid number';
}
}
</script>
</body>
</html>

This HTML file includes a simple form with an input field for feet and a button to trigger the conversion. The JavaScript function `convertFeetToKilometers()` is called when the input changes or when the button is clicked, and it performs the conversion and displays the result.