SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can somene help me create a milage script?

    I am trying to create a basic javascript that shows milage between severag areas, similar to what you find on the rear road atlas.
    I have tried and failed to create anything, i just think i am total useless at understanding javascript.

    The basic concept is this image attached.

    There would be a drop down box that lists the destinations and another with the same but would be departure.
    When a person chooses example: Butte >>> Kalipsell it would show 238 and vice versa.
    it seems a simple thing to do but cant get my head around it all.
    Could someone create a simple script, say 3 destinations and i will fill the rest in and see if i can understand what i am doing and then ask for additional help if required?
    Attached Images Attached Images

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Here's one way to do it.

    Code javascript:
    var locations = {
        'Billings': {
            'Bozeman': 143,
            'Butte': 228
        },
        'Bozeman': {
            'Billings': 143,
            'Butte': 86
        },
        'Butte': {
            'Billings': 228,
            'Bozeman': 86
        }
    };
    createLocations(locations, 'mileage');

    You might want to break down the createLocations function in to several different ones though, such as:

    Code javascript:
    function createCells(cells, type) {
        ...
    }
    function createTable(data) {
        ...
    }
    function createLocations(locations, target) {
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •