SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Generating javascript variables

    HI All,

    I am trying to generate javascript variables. It looks right in the source, but causes a problem.

    Can someone have a look and tell me why.

    I have a php script that is pulling out a load of map icons from a database:

    www.southhams.org/map.php
    www.southhams.org/map.php?test=test

    Thanks

    Will

  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)
    Quote Originally Posted by tangledman View Post
    Can someone have a look and tell me why.
    Code:
    var 1 = '/images/map_icons/airport.png';
    var 2 = '/images/map_icons/artgallery.png';
    var 3 = '/images/map_icons/bank.png';
    ...
    It is invalid to use a number as an identifier.
    What you can do is to use an array to store the info, so that you can then use an array index to retrieve the values:


    Code javascript:
    var icons = [
        '/images/map_icons/airport.png',
        '/images/map_icons/artgallery.png',
        '/images/map_icons/bank.png',
        ...
    ];
    Last edited by paul_wilkins; Jul 23, 2011 at 02:31.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul. "It is invalid to use a number as an identifier." - all I need


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
  •