Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    :: help with dimentional arrays ::

    ok i have this :

    <a href="javascript:;" onMouseOut="document.construction_name.src='images/construction_img0.gif'; (window.status='Welcome to Simons'); return true;" onMouseOver=" hide('group_layer'); hide('construction_layer'); hide('estates_layer'); hide('blanker_layer'); hide('simonstogether_layer'); hide('suppliers_layer'); hide('links_layer'); show('construction_layer'); document.construction.src='images/construction1_img.gif'; (window.status='Construction >'); return true"><img name="construction_name" src="images/construction_img0.gif" height="19" border="0"></a>

    which needs to be written quite a few times..

    so i thought - woohoo time to try and do an array... unfortunately i forgot i was dumb so i need some help...

    basically i have this so far:

    <script>

    function mainLinks () {
    }

    linkRay = new Array()
    linkRay[0] = new Array("javascript:;","group")
    linkRay[0] = new Array("javascript:;","construction")
    linkRay[0] = new Array("javascript:;","estates")
    linkRay[0] = new Array(" 'http://www.simonsdesign.com' target='blank' ","design")
    linkRay[0] = new Array(" 'http://www.wrights-construction.com' target='blank' ","wrights")
    linkRay[0] = new Array(" 'http://www.qdsltd.com/' ","qds")
    linkRay[0] = new Array("javascript:;","simonstogether")
    linkRay[0] = new Array("javascript:;","suppliers")
    linkRay[0] = new Array("javascript:;","links")
    linkRay[0] = new Array("javascript:;","search")
    linkRay[0] = new Array("javascript:;","help")

    for (wrin=0;wrin<linkRay.length;wrin++) {

    document.write('<a href="+linkRay[wrin][1]+"

    \n\n');}


    </script>

    am i going in the right direction? it dont seem to do anything so far

    help plz!! thanksssssssssss!!!!!!!!!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just learned how to do this. This is what I found out.

    var outline = new Array(5);
    for(var i=0; i<outline.length; i++) {
    outline[i] = new Array();
    }
    outline[0][0]="Shoes";
    outline[0][1]="Price range";
    outline[0][2]="Life range";
    outline[0][3]="Two important conditions of shoes";
    outline[1][0]="Clothing";
    outline[1][1]="Socks";
    outline[1][2]="Underwear";
    outline[1][3]="T-shirts";
    outline[1][4]="Shorts";
    outline[1][5]="Sweats";
    outline[1][6]="Accessories and other";
    outline[2][0]="Weather";
    outline[2][1]="Heat";
    outline[2][2]="Cold";
    outline[2][3]="Humidity";
    outline[2][4]="Seasons";
    outline[2][5]="Altitude";
    outline[3][0]="Warm-up";
    outline[3][1]="Description";
    outline[3][2]="Benefits";
    outline[4][0]="Cool-down";
    outline[4][1]="Description";
    outline[4][2]="Benefits";

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not quite sure to me what you want to achieve (and how it would be a timesaver), but I believe that I spotted some weak points in your script.
    You don't add new elements to the linkRay array, you constantly overwrite the first element (linkRay[0]). So, at the end you have an array that consists only of one single element.
    Also, it may not show something because you're writing an incomplete tag. It's just the beginning of the <a> tag, and linebreaks within the parameter for document.write are not allowed.
    So basically, perhaps this will put you on the right track:

    Code:
    linkRay = new Array()
    linkRay[linkRay.length] = new Array("java script:;","group")
    linkRay[linkRay.length] = new Array("java script:;","construction")
    linkRay[linkRay.length] = new Array("java script:;","estates")
    linkRay[linkRay.length] = new Array(" 'http://www.simonsdesign.com' target='blank' ","design")
    linkRay[linkRay.length] = new Array(" 'http://www.wrights-construction.com' target='blank' ","wrights")
    linkRay[linkRay.length] = new Array(" 'http://www.qdsltd.com/' ","qds")
    linkRay[linkRay.length] = new Array("java script:;","simonstogether")
    linkRay[linkRay.length] = new Array("java script:;","suppliers")
    linkRay[linkRay.length] = new Array("java script:;","links")
    linkRay[linkRay.length] = new Array("java script:;","search")
    linkRay.push(new Array("java script:;","help"));
    
    for (wrin=0;wrin<linkRay.length;wrin++) {
    
    document.write('<a href="' + linkRay[wrin][0] + '">' + linkRay[wrin][1] +'</a><br>');
    
    }
    Obs: I used two different techniques to append a new element to an array. Either use the current length as the index number for the new element, or push() the new element to the array. Both work similarly, use what you prefer.

    hth

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    basically babel your main snag is redefining linkray[0] over and
    over.

    linkray = new Array() <--- tells browser we want a new array with an unspecified number of parts. These would be linkray[0]
    linkray[1] linkray[2] etc. You named all yours linkray[0].

    Subnote linkray[] without a number would be one higher than the highest yet defined - eg linkray[0] = ""; linkray[] = "asd" the [] would now be the same as 1

    So either number them all sequentially or remove ALL the
    [numbers]

    At the base we have

    for (wrin=0;wrin<linkRay.length;wrin++) {


    the var wrin is incremented from zero up to one less than the
    length of the array linkray - as arrays are numbered from zero
    also that would cover the lot

    document.write('<a href="+linkRay[wrin][1]+"

    The first run of the for loop has wrin equal to zero - so
    ="+linkRay[wrin][1]+" inserts the value of linkray[0][1]

    Big note: All array thingies start at zero -

    linkRay[0] = new Array("java script:;","group")

    now linkray is an array so it has the parts
    linkray[0][0] = "javascript:;"
    linkray[0][1] = "group"

    because we use the same parts [0][0] and [0][1] in set parts of
    the doc write, we increment the first array definer [var][0] [var][1]

    Anyway, have another go after renumbering your array
    definitions.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another note

    linkRay[3] = new Array(" 'http://www.simonsdesign.com' target='blank' ","design")

    document.write('<a href='+linkray[3][0]+' ...>

    would yield --- <a href= 'http://www.simonsdesign.com' target='blank' .....>

    not overly bad - you might glitch pretty soon doint that sort of
    thing though - I now tend to write with docwrites setting double
    quotes in the output
    document.write('<a href="'+linkray[3][0]+'">');
    for that to work with your array declares you'd need to either
    define the arrays in single quotes or escape the "

    linkRay[3] = new Array('http://www.simonsdesign.com" target="blank','design')
    or
    linkRay[3] = new Array("http://www.simonsdesign.com\" target=\"blank","design")

    Hope that didn't confuse you too much.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Originally posted by Ökii

    Subnote linkray[] without a number would be one higher than the highest yet defined - eg linkray[0] = ""; linkray[] = "asd" the [] would now be the same as 1

    So either number them all sequentially or remove ALL the
    [numbers]
    I think you are thinking of php. You can't just leave the brackets empty in JavaScript without throwing up all kinds of errors.

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh... mikeolone's post actually helped me out... that's all there is to 2D arrays?!?! They always looked hard... lol

    That seems rather simple to me now... I'm going to go play around with it.

    I assume you could do something like

    arrayname[1].length

    to determine how many of the "subthingies" are in that part of the array, right? Like:

    arrayname[1][0] = "one"
    arrayname[1][1] = "two"
    arrayname[1][2] = "three"

    if I said:

    alert(arrayname[1].length);

    would it say 3?

    (How do you like that technical explanation? Hope you know what I mean... lol)

    Thanks.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    /me kicks himself ... this is the problem with rushing stuff near the end of the day

    thanks for all that helped...

    no doubt i will still enquire again as this is a pretty long string to be written and lots of quotes which will get VERY confusing for me
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    quick update:


    <html>
    <head>
    <title>arraytest</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <style type="text/css">
    .display {
    visibility:hidden;
    background-color:#eeeeee;
    color:#333333;
    font-family:verdana;
    position:absolute;
    font-size:12px;
    width:200px;
    left: 20px;
    top: 100px;
    }
    </style>

    <script language="JavaScript">
    <!--
    function show(object) {
    if (document.getElementById && document.getElementById(object) != null)
    node = document.getElementById(object).style.visibility='visible';
    else if (document.layers && document.layers[object] != null)
    document.layers[object].visibility = 'visible';
    else if (document.all)
    document.all[object].style.visibility = 'visible';
    }

    function hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
    node = document.getElementById(object).style.visibility='hidden';
    else if (document.layers && document.layers[object] != null)
    document.layers[object].visibility = 'hidden';
    else if (document.all)
    document.all[object].style.visibility = 'hidden';
    }
    //-->
    </script>
    </head>
    <body bgcolor="#FFFFFF">

    <div id="Grouplayer" class="display">group</div>
    <div id="Constructionlayer" class="display">const</div>
    <div id="Estateslayer" class="display">estates</div>
    <div id="Blankerlayer" class="display">blanker</div>
    <div id="Simonstogetherlayer" class="display">simonstogether</div>
    <div id="Supplierslayer" class="display">suppliers</div>
    <div id="Linkslayer" class="display">links</div>
    <div id="Searchlayer" class="display">search</div>
    <div id="Helplayer" class="display">help</div>
    <div id="Designlayer" class="display">design</div>
    <div id="Wrightslayer" class="display">wrights</div>
    <div id="QDSlayer" class="display">qds</div>

    <script language ="javascript" type="text/javascript">
    function hideall()
    {
    hide('Grouplayer');
    hide('Constructionlayer');
    hide('Estateslayer');
    hide('Blankerlayer');
    hide('Simonstogetherlayer');
    hide('Supplierslayer');
    hide('Linkslayer');
    hide('Searchlayer');
    hide('Helplayer');
    hide('Wrightslayer');
    hide('QDSlayer');
    hide('Designlayer');
    }

    function returnstatus() {
    (window.status='Welcome to the Simons Group');
    return true;
    }

    linkRay = new Array()
    linkRay[0] = new Array("javascript:;","Group")
    linkRay[1] = new Array("javascript:;","Construction")
    linkRay[2] = new Array("javascript:;","Estates")
    linkRay[3] = new Array("http://www.simonsdesign.com\" target=\"blank","Design")
    linkRay[4] = new Array("http://www.wrights-construction.com\" target=\"blank","Wrights")
    linkRay[5] = new Array("http://www.qdsltd.com\" target=\"blank", "QDS")
    linkRay[6] = new Array("javascript:;","Simonstogether")
    linkRay[7] = new Array("javascript:;","Suppliers")
    linkRay[8] = new Array("javascript:;","Links")
    linkRay[9] = new Array("javascript:;","Search")
    linkRay[10] = new Array("javascript:;","Help")

    for (wrin=0;wrin<linkRay.length;wrin++) {

    document.write('<a href=\"'+linkRay[wrin][0]+'\" onMouseout=\"document.'+linkRay[wrin][1]+'name.src=\'images/'+linkRay[wrin][1]+'img0.gif\'; returnstatus();\" onMouseOver=\"hideall(); show(\''+linkRay[wrin][1]+'layer\'); document.'+linkRay[wrin][1]+'name.src=\'images/'+linkRay[wrin][1]+'img1.gif\'; (window.status=\''+linkRay[wrin][1]+'\'); return true;\"><img name=\"'+linkRay[wrin][1]+'name\" src=\"images/'+linkRay[wrin][1]+'img0.gif\" border=\"0\"></a>\n\n ');
    }
    </script>

    </body>
    </html>


    works a treat in NS and IE

    i think a problem was that IE isnt case sensitive but NS is...

    eg Constructionimg isnt the same as constructionimg ?!?!

    lol i tyhink i must have taken 3 hours to realise that!!!!!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

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