Highlight cells with past dates
<p>Hi guys I dont know if this is something that a new programmer should true or not, but heres my problem. I have a table of 13 columns at at present about 400 rows. yes i nkow this is a large table and unfortunatley it will only be getting bigger.  what i am trying to achive with this table, somehow, is to have a function that checks the cell contents ( a date dd/mm/yyyy) in the 12th coloumn and if the date has past that it will will add a css to the row.</p>

<p>Through help from some very intelligent programmers i have a code that should work. but i cant get it to work in any way.</p>

<p>Can anyone help me out with this problem.</p>

<p>Thanks.</p>

<p>The code that i have is:</p>

<pre><code>&lt;script language="javascript"&gt;
$(document).ready(function() {
function parseDate(dateString)
{
return new Date(Date.parse(dateString));
}

$('#names tr').each(function(index)
{
var row = $(this);
if (parseDate(elem.find("td:eq(1)").text()) &lt; new Date())
row.addClass('row');
});
});

&lt;/script&gt;
</code></pre>

<p>My table is set out like this:</p>

<pre><code>&lt;tr&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;Date&lt;/td&gt;
&lt;td&gt;Date&lt;/td&gt;
&lt;td&gt;Data&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>ok and this is what i have now:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
#sprog tr {
background: #00FF00;
}

#sprog tr.past {
background: #FF0000;
}
&lt;/style&gt;
&lt;script src="jquery 1.4.2.js"&gt;&lt;/script&gt;
&lt;script&gt;
$(function()
{
$('#sprog .date').each(function()
{
var row_date = Date.parse($(this).text().replace(/(\d{2})\/(\d{2})\/(\d{4})/, '$2/$1/$3'));
var now_date = new Date().getTime();
if(row_date &lt; now_date)
{
$(this).parent('tr').addClass('past');
}
}
);
}
);
&lt;/script&gt;
&lt;title&gt;cells&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;table id="sprog"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;14/08/2010&lt;/td&gt;
&lt;td&gt;20/10/2015&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td class="date"&gt;14/10/2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td class="date"&gt;04/10/2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10/12/2010&lt;/td&gt;
&lt;td class="date"&gt;12/10/2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12/10/2010&lt;/td&gt;
&lt;td class="date"&gt;01/01/1900&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
