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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with some code inside a for loop

    My JavaScript code goes through a for loop and outputs pictures in a table. The problem is that if there are 36 or so pictures, the table stretches the page. After about every 4 pics, I want a </tr><tr> placed into the code. Is it possible to do that?

    Code:
    for (var i = 0; i < photos.length; i++)
    {
    	document.write('<td><a href="images/' + photos[i] + '.jpg" title="Click to enlarge" rel="lytebox">');
    	document.write('<img src="images/' + photos[i] + '.jpg" alt="" class="small" /></a><br />');
    	document.write('Photo ' + (i + 1) + '</td>');
    }

  • #2
    New Coder
    Join Date
    Feb 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not sure but his might help

    Code:
    document.write('<tr>');
    for (var i = 0; i < photos.length; i++)
    {
    	document.write('<td><a href="images/' + photos[i] + '.jpg" title="Click to enlarge" rel="lytebox">');
    	document.write('<img src="images/' + photos[i] + '.jpg" alt="" class="small" /></a><br />');
    	document.write('Photo ' + (i + 1) + '</td>');
            if(i &#37;4 == 0)
            {
                    document.write('</tr>');
            }
    }


  •  

    Posting Permissions

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