0

I have the following code:

<td bgcolor="#FF0000"><center>
    <? echo $rows['msisdn']; ?>
</td>
<td align="center" bgcolor="#FFFFFF">
    <a href="control_clientinfo.php?member_id=<? echo $rows['member_id']; ?>"
    class="update">Look Up</a>
</td>

This draws data from mysql for me and does what it needs to do, question

<td bgcolor="#FF0000">
    <center>
    <? echo $rows['msisdn']; ?>
</td>

How do I change that background colour once the link has been visited. I know how to change the visited link colour but i want to change the table viewed colour.

Is this possible or am I biting into a rock?

Highway of Life
  • 22,803
  • 16
  • 52
  • 80
  • possible duplicate of [Apply CSS styles to an element depending on its child elements](http://stackoverflow.com/questions/2326499/apply-css-styles-to-an-element-depending-on-its-child-elements) – Tom Walters Mar 14 '13 at 16:45
  • Is it possible to take color of link using jQuery and update color of the cell? – dikirill Mar 14 '13 at 16:45
  • You may want to look into CSS for what you want to do. It's quite expressive and can accomplish this easily. –  Mar 14 '13 at 16:45
  • 1
    I don't think you can. You'd probably have to set a cookie to see if the page has been visited and if so, change the BG color. – KleverKrypto Mar 14 '13 at 16:48
  • @DwightScott You can, but it requires Javascript. – Highway of Life Mar 14 '13 at 17:19
  • @HighwayofLife Right, and as noted in your answer, if you revisit the page, the color is lost. Which kind of defeats the purpose of changing the color if visited. Hence my comment of setting a cookie and basing the logic from that. Also, the demo of the plugin you suggested, didn't seem to work for me. Perhaps I did something wrong. – KleverKrypto Mar 14 '13 at 17:41
  • @DwightScott, you're correct, the only way to do this would be to track the clicks using JS/jQuery and set a cookie to be maintained across page refreshes. – Highway of Life Mar 15 '13 at 04:49

3 Answers3

0

Updated Answer

The browser controls the visited link status, there's no way to determine this with Javascript or CSS for the security of users. This may have worked in the past, but no longer works on all modern web browsers. -- This is done to prevent history tracking by the browsers themselves. The only workaround for this would be to track which links were clicked using Javascript event handlers and if you want this information persistant across multiple page-loads/refreshes, you'll need to set a cookie.

For current page, you could use Javascript (or better yet, jQuery) to change the color of your background.

Using jQuery:

$("td a").click(function() {
    $(this).parent("td").addClass('clicked');
});

On a related note, I highly recommend NOT using <center> and the bgcolor and align attributes. Those have long been deprecated in recent HTML versions. Consider using CSS for all of your "center" and styling/background color needs.

Highway of Life
  • 22,803
  • 16
  • 52
  • 80
0

Nothing much to do with PHP I'm afraid, more of a Javascript problem.

Try Remy Sharp's jQuery plugin http://remysharp.com/2008/02/25/visited-plugin/

Identical code is in this answer https://stackoverflow.com/a/1791790/932508

Community
  • 1
  • 1
Mei Gwilym
  • 397
  • 5
  • 15
-1

Add onclick function in table column with anchor tag

<td align="center" bgcolor="#FFFFFF" onclick="document.getElementById("demo").style.backgroundColor="RED";"> <a href="control_clientinfo.php?member_id=<? echo  $rows['member_id']; ?>" class="update">Look Up</a></td>

Then add an Id tag to other table column for which you want to change background color.

<td id="demo" bgcolor="#FF0000">
  <center>
  <? echo $rows['msisdn']; ?>
  </center>
</td>
Ritesh Chandora
  • 8,382
  • 5
  • 21
  • 38