Sunday, December 11, 2016

Kilometers To Miles Converter in JavaScript

Here is a sample program that I wrote a long time ago during the time I work as IT instructor in college. This program will ask the user to give a number in kilometers and then our program will convert the given number into miles equivalent using JavaScript.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<title> Kilometers to Miles Converter 1.0
</title>
<body bgcolor="black">
<font color="white" face="Arial" size="5">
<center>
<br>
   Kilometers to Miles Converter 1.0
<br>
</center>
</font>
<style type="text/css">
.labelText {
 text-align : right;
 padding-right : 3px;
 color   : white;
 font-family:"Arial";
 font-size    : 18px;
}
</style>

 <form  name="kilo" method="post">
<table>
<tr>
<tr>
 <td> &nbsp; </td>
 </tr>
<td class="labelText">  Enter Number of Kilometers

</td>
<td> <input type="text" name="distance"  size="10"/> </td>
</tr>

 <tr>
 <td> &nbsp; </td>
 </tr>
</td>
<tr>
<td class="labelText">
The result is
</td>
<td> 
<input type="text" name="display"  size="50"/> </td>
 </tr>
  <tr>
 <td> &nbsp; </td>
 </tr>
</td>
<td> <input type="button" value="Compute" 
title="Click here to compute the miles equivalent."
 onClick="compute1()">
</td> 
<td> <input type="button" value="Clear" 
title="Click here to clear the text box."
 onClick="clear_all()">
</td> 

</table>
</font>
</form>
<script language ="javascript">
function compute1()
{
var xval1, solve1,final_result;
var result;
  
value1 = parseInt(document.kilo.distance.value);
              
solve1 = (value1 * 0.621371192);
// For two decimal places convertion
final_result = Math.round(solve1 * 100) /100;

result = value1 + " kilometers(s) is equivalent to " 
               + final_result + " miles(s). ";

document.kilo.display.value = result;
}

function clear_all()
{
document.kilo.distance.value = "";
document.kilo.display.value = "";
document.kilo.distance.focus(); 
}
</script>
</body>
</html>








No comments:

Post a Comment