SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Simple Array

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Array

    Im new to JavaScript so take it steady, i have an array:

    <script type="text/javascript">

    var colOne [0] = new Array("Copyright", "Council - spending plans - consultation", "Data protection");
    var colTwo [1] = new Array("Digital Region", "Freedom of information", "Libraries - online information resources");
    var colThree [2] = new Array("Our standards", "Test"};


    document.write(colOne[0]);


    </script>

    anyone can tell why it does not work?

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    Code:
     
    var colOne = new Array("Copyright", "Council - spending plans - consultation", "Data protection");
    var colTwo  = new Array("Digital Region", "Freedom of information", "Libraries - online information resources");
    var colThree  = new Array("Our standards", "Test"};

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks

  4. #4
    SitePoint Addict
    Join Date
    Nov 2008
    Location
    Shropshire, England
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've got a syntax error in there. Easily done.

    var colThree = new Array("Our standards", "Test"};

    Should be var colThree = new Array("Our standards", "Test");

    What you were doing did look a bit like a multi-dimensional array. So another alternative

    Code:
    // make an array
    var row = new Array();
    
    // then populate the row array with new arrays
    row[0] = new Array("Copyright", "Council - spending plans - consultation", "Data protection");
    row[1] = new Array("Digital Region", "Freedom of information", "Libraries - online information resources");
    row[2] = new Array("Our standards", "Test");
    
    document.write(row[0]); // "Copyright", "Council - spending plans - consultation", "Data protection"

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do i then get the next list to appear next to it, so it looks like it has a 3 column layout?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by swfc4lyf View Post
    how do i then get the next list to appear next to it, so it looks like it has a 3 column layout?
    Here's how to do it using CSS.
    CSS Swag: Multi-Column Lists

    From there it's just a matter of using JavaScript if necessary to spoon-feed the appropriate info to the presentation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unable to get it to output the way it does on the link you sent, if you can show me how to get it to output like you have from numbers one to ten it would greatly be appreciated.


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
  •