Alternating content in a table using Javascript?

Discussion in 'HTML & Website Design' started by yfs1, Apr 18, 2008.

  1. #1
    Does anyone know if its possible to (or how to) change go through a series of tables on an html site?

    I have three tables the exact same as below with quotes but I only want to display one at a time and rotate through them.

    Is js the best way or can someone propose another method? (Keep in mind it has to hold its layout)


    <table style="width: 100%;" cellspacing="6" cellpadding="6" border="0">
                        <tbody>
                         <tr>
                              <td width="6%" rowspan="2" valign="top"><img src="http://www.sample_image.jpg" alt="test" width="34" height="45" /></td>
                               <td width="94%"><div align="right"><img src="http://www.sample_image.jpg" alt="quotes" width="12" height="9" />Please ignore this box as it is under construction<img src="http://www.sample_image.jpg" alt="quote" width="12" height="9" /><br />
                               </div></td>
                         </tr>
                                      <tr>
                                         <td><div align="right">- unknown </div></td>
                                      </tr>
     </tbody>
     </table>
    Code (markup):

     
    yfs1, Apr 18, 2008 IP
  2. Bagi Zoltán

    Bagi Zoltán Well-Known Member

    Messages:
    364
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #2
    If I were you I would place the codes of the three tables into three different php file: table1.php, table2.php and table3.php.
    Into the file you would like the tables randomly display place this code

    <?php 
    $random=rand(1, 3);
    include 'table'.$random.'.php';
    ?>
    Code (markup):
    You may make the html file extension to get parsed as a php script if your server software is Apache by adding this code into the .htaccess file.
    AddType application/x-httpd-php .php .htm .html
    Code (markup):
     
    Bagi Zoltán, Apr 18, 2008 IP
  3. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #3
    And if I wanted it to fade between them say every 3 seconds? (Rahter then a random static display)
     
    yfs1, Apr 18, 2008 IP
  4. Bagi Zoltán

    Bagi Zoltán Well-Known Member

    Messages:
    364
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #4
    If you want it to get fade I would use timed ajax requests and would play with the opacity to give fancy look.
     
    Bagi Zoltán, Apr 18, 2008 IP
  5. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yfs1, Apr 18, 2008 IP
  6. Bagi Zoltán

    Bagi Zoltán Well-Known Member

    Messages:
    364
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #6
    I'm glad that i could help you!:)
     
    Bagi Zoltán, Apr 18, 2008 IP