Jump to content

two CSS Zebra table created from loop


Meni

Recommended Posts

Hello.

I have a loop that creates a table from mysql data:

[code]echo '<table border="1" bordercolor="#CFCFCF" align="center">';// a new table for every user...[/code]

I have a javascript function that turns this table into a striped table:

[code]<script language="javascript"><!--
function zebraTable() {
    // get the table
    var t = document.getElementById('zebra');

    // set the class name
    var theClass = "evenRow";

    // get a collection of rows
    var rCol = t.rows;

    // declare the counter
    var rowNum = 0;

    // loop through each row
    for (var i = 0; i < rCol.length; i++) {
        // apply the class name
        if (i % 2 == 0) rCol[i].className = theClass;
    }
}

onload = zebraTable;

--></script>[/code]

This javascrpit will inspect the ID of the table and if it's "zebra" it will stripe it.

All is well untill i want to have two or more tables in one page.

I can't name all of them "zebra" because it will only stripe the first table.

How do i go around this?
Link to comment
https://forums.phpfreaks.com/topic/15787-two-css-zebra-table-created-from-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.