1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Distance Calculator

Friday June 19, 2009
How far is it between two places? Make your own JavaScript calculator to display the distances between your choice of locations.

This JavaScript "calculator" will allow visitors to your site to obtain the distance between two cities (or other locations) by selecting the start and end points for their journey from two drop down lists. You can set up whatever locations that you like for the "calculator" simply by setting up the places and distances between them in the array structure at the top of the JavaScript.

Distance Calculator
Comments
May 3, 2006 at 3:42 pm
(1) Maurice says:

You say copy and paste in a file called
dist.js . How do I gain access or create such a file. I tried everything I know to place the Distance Calculator on my page but get stuck at this last instruction, which is to copy and paste in the dist.js file.

May 4, 2006 at 3:34 am
(2) javascript says:

1. Open your favourite plain text editor – perhaps notepad if you are using Windows or vi or emacs on Linux.

2. Copy the content for the dist.js file from the page and paste it into the empty page in the editor.

3. Save the file with the name dist.js

4. Upload the file to the folder on your site where you uploaded the page that refers to it.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

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.