1. Home
  2. Computing & Technology
  3. JavaScript

Distance Calculator with Times

2. Get the Code

clr gif
Join the Discussion

Questions? Comments?

To insert the time/distance calculator into your page the first thing you need to do is to put the following HTML into the body of your page where you want the calculator to appear. (You can modify the text descriptions of the fields if you like).

You also need to add a small piece of HTML into the head of your page that will link the Javascript into the page so that the calculator will function.

<script type="text/javascript" src="dist.js"></script>

Next, copy the following Javascript code and save it in a file called dist.js (which you have just linked into your page. Don't worry about the fact that the cities in the array are not the ones you want - we'll fix that afterwards).

All that remains now is to modify the time/distance array so that it contains the cities you want along with the correct distances and times between them.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.