Advanced Search

Results 1 to 2 of 2

Thread: loop help to reduce redundant code

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default loop help to reduce redundant code

    I have this code:

    Code:
    function gelding()
    {
    document.getElementById('breed').innerHTML=txt2;
    var tablehead = "<table border=1><tr><th>Name</th><th>Sire</th><th>Dam</th><th>Height</th><th>Price</th></tr>";
    var id2="";
    id2 += ("<tr>");
    
    
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22511[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21221[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21131[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21231[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21112[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21111[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22411[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22311[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21241[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21211[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21212[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22231[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22111[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22441[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21441[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id22331[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21311[x]+"</td>");}
    id2 += ("</tr><tr>"); for (var x=0;x<5;x++) { id2 += ("<td>"+id21141[x]+"</td>");}
    id2 += ("</tr></table>");
    
    document.getElementById('horse').innerHTML=tablehead+id2;
    }
    I would like to consolidate this into a for or while loop.

    the variables for the above code are:
    Code:
    var id21111=new Array("Matrix","Armani FC","Magnolyah","15.2","$$$");
    var id21112=new Array("Unregistered","Armani FC","Lots n Lots of Fame","15.2","$$$");
    var id21211=new Array("Fascination PA","Armani FC","Veranda","15.3","$$$");
    var id21212=new Array("Whiskey Moon","Bucharest V","Aerial Moondanse","14.3","$$$");
    var id21311=new Array("Khabernet","Versace","Khabaret","?","$$$");
    var id21221=new Array("Elite Design","Armani FC","Allioness","15","$$$");
    var id21231=new Array("Spartacus PA","Armani FC","Autumn Sihouette","15","$$$");
    var id21131=new Array("High Frequency","Armani FC","Allioness","15.1","$$$");
    var id21241=new Array("Grey Hawk","Armani FC","Tennacite","15","$$$");
    var id21131=new Array("High Frequency","Armani FC","Allioness","15.1","$$$");
    var id22511=new Array("Wild Fire PE","Afire Bey V","GTF Judy, Judy, Judy","?","$$$");
    var id22411=new Array("Pandamonium","Armani FC","Mimone (DHH)","?","$$$");
    var id22441=new Array("The Elegant Edition","Jonker (DHH)","Autumn Elegance","?","$$$");
    var id22331=new Array("Pizzazz PE","Picazso","Painted Lady","?","$$$");
    var id22231=new Array("Show Me the Cash","Bucharest V","Moonshyne","?","$$$");
    var id22111=new Array("Alacazam","Jonker (DHH)","Aerial Moondanse","?","$$$");
    var id22311=new Array("Mandrini","Armani FC","Sendrini (DHH)","?","$$$");
    var id21441=new Array("Maverick PA","Masquerade PA","Versiara","?","$$$");
    var id21141=new Array("Silver Dollar","Versace","Taffettaa","?","$$$");
    Any help in this matter would be greatly appreciated.
    Thanks.
    Last edited by Snookerman; 06-22-2009 at 03:29 PM.

  2. #2
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    a working copy of this can be found at www.pegasusarabians.com/new (current as of 1123 22jun09)

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
  •