SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Array Problems

  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Yorkshire, mississippi
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Problems

    Can someone please help me out here;

    Im trying to get the arrays to be outputted ( using a script not shown) in the same order as they are in the array.

    But they seem to be outtputted in any old fashion, randomly if you will once i test the page.

    Can any advanced Jscripters help me out please?
    Heres the snippet of what it looks like;

    Kind Regards
    ===
    JS
    ===
    var rates = {
    '11¢' : 'Afghanistansp',
    '2¢' : 'Afghanistanw2f',
    '4¢' : 'Afghanistanspp',
    '3¢' : 'Afghanistan5',
    '15¢' : 'Afghanistansp',
    '23¢' : 'Afghanistanw2f',
    '45¢' : 'Afghanistanspp',
    '5¢' : 'Afghanistan5'
    }
    =====
    HTML
    =====
    <form>
    <select class="country" onchange="front();" name="main">
    <option selected="selected">-Select from the list</option>
    <script type="text/javascript">
    for( var opt in rates ) {document.write( '<option value="' + opt + '">' + rates[opt ] + '</option>' );}
    </script>
    </select>
    </form>

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Poland
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should help:
    Code:
    <script type="text/javascript">
    var rates = [
        ['11&cent;' , 'Afghanistansp'],
        ['2&cent;' , 'Afghanistanw2f'],
        ['4&cent;' , 'Afghanistanspp'],
        ['3&cent;' , 'Afghanistan5'],
        ['15&cent;' , 'Afghanistansp'],
        ['23&cent;' , 'Afghanistanw2f'],
        ['45&cent;' , 'Afghanistanspp'],
        ['5&cent;' , 'Afghanistan5']
    ];
    
    </script>
    
    <form>
        <select class="country" onchange="front();" name="main">
        <option selected="selected">-Select from the list</option>
            <script type="text/javascript">
                for (var i = 0; i < rates.length; i++) {
                    document.write('<option value="' + rates[i][0] + '">' + rates[i][1] + '</option>');
                }
            </script>
        </select>
    </form>

  3. #3
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Yorkshire, mississippi
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot, can you breakdown what i was doing wrong, or what i wasnt doing right?


    Kind regards

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Poland
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not using an array.
    Code:
    // this is an object - a short way to define properties
    var test1 = {'a' : 12, 'b': 14};
    // this is also an object
    var test2 = function() { this.a = 12; this.b = 14; }
    
    // this is an array
    var test3 = [12, 14];
    // this is a multidimensional array
    var test4 = [[12, 14], [16, 18]];


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
  •