1. Home
  2. Computing & Technology
  3. JavaScript

Distance Calculator with Times and Costs

1. Introduction and Sample

Join the Discussion

Questions? Comments?

More of this Feature

Get the Script Modify the Code

This variant of my distance calculator not only displays the distances and times between each of your selected cities/locations, it also displays the cost of travelling between those locations as well. In fact if you don't want times and costs but want two other values based on the two selected locations then you can just change the field descriptions from time and cost to whatever it is that you do want.

The following example displays the distances, times, and costs between ??? but the script can be easily adapted to work with any locations simply by entering the names of the locations and the distance, times, and cost of travelling between them into a multi-dimensional array. The script simply requires starting and destination cities to be selected and the distance, time, and cost of travel between them will be extracted from the array and displayed.

Starting City:
Destination City:
Distance: Miles
Travel Time: Minutes
Cost ($):

If you want to add a copy of this time/distance calculator to your site then the first thing you need to do is to get the HTML and Javascript.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.