Kilometers/Miles Converter
Kilometers/Miles Converter using Javascript
This simple Program will take input in Kilometers and convert it to Miles and vice versa.
HTML with Javascript
<!DOCTYPE html>
<html>
<title>Kilometers/Miles Converter</title>
<body bgcolor="lightgreen">
<h2>Kilometers/Miles Converter</h2>
<p>Type a value in Kilometers to convert to Miles:</p>
<p>
<label>Kilometers</label>
<input id="k" type="number" placeholder="000" oninput="Convert(this.value)" onchange="Convert(this.value)">
</p>
<p>Miles: <span id="Miles"></span></p>
<script>
function Convert(km) {
document.getElementById("Miles").innerHTML=km*0.62137;
}
</script>
<p>Type a value in Miles to convert to Kilometers:</p>
<p>
<label>Miles</label>
<input id="m" type="number" placeholder="000" oninput="ConvertM(this.value)" onchange="ConvertM(this.value)">
</p>
<p>Kilometers: <span id="km"></span></p>
<script>
function ConvertM(m) {
document.getElementById("km").innerHTML=m/0.62137;
}
</script>
</body>
<html>
Comments
Post a Comment