I've a list of data from db which I'm showing in each row on a Table. I want when I click a row it's should be remain highlighted with color. But my following code is highlighting all row. Can you help me about it.
It's should be highlight only one row which I clicked.
My code
<script type="text/javascript">
function visited(a) {
tr = a.parentNode.parentNode;
tr.style.backgroundColor = "red";
}
</script>
<?php
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
echo "<thead>";
echo "<tr>";
echo "<td class='' valign='top' width='200'></td>";
echo "<td class='' valign='top' width='125'></td>";
echo "<td class='' valign='top' width='125'></td>";
echo "<td class='' valign='top' width='125'></td>";
echo "<td class='' valign='top' width='125'></td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($res = mysql_fetch_array($get)){
$cdid = $res['cdid'];
$family_name = $res['family_name'];
$given_name = $res['given_name'];
$work_phone = $res['work_phone'];
$mobile_phone = $res['mobile_phone'];
$email = $res['email'];
$email_private = $res['email_private'];
$cid = $res['cid'];
$department = $res['department'];
$title = $res['title'];
$getComapnyName = mysql_query("SELECT company_name FROM company WHERE cid = '$cid' ");
$resCompany = mysql_fetch_array($getComapnyName);
$companyName = $resCompany['company_name'];
if (strlen($companyName) >= 20) {
$companyName = substr($companyName, 0, 10). " ... " . substr($companyName, -5);
}else{
$companyName = $companyName;
}
echo "<tr onclick='getDetails($cdid),showNotexBox($cdid),showAllNotesBox($cdid), visited(this);'>";
echo "<td class='' valign='top'>$companyName</td>";
echo "<td class='' valign='top'>$family_name</td>";
echo "<td class='' valign='top'>$given_name</td>";
echo "<td class='' valign='top'>$department</td>";
echo "<td class='' valign='top'>$title</td>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>