Solved

Change bgcolor on click...then change back....

Posted on 2004-09-13
5
259 Views
Last Modified: 2012-06-27
Hi,
I have a table that is built dynamically with PHP that contains a link to change the location of an iframe.  I want the tabel row to change color when this link is clicked, then if the use selects another link, that row changes colow, and the first will change back to its original.
How can I accomplish this?
Thanks!
0
Comment
Question by:maunded
5 Comments
 
LVL 3

Expert Comment

by:Sasho
ID: 12050291
Take a look at this and see if it is what you are looking for: http://tech.irt.org/articles/js207/
Here is what it actually looks like: http://tech.irt.org/articles/js207/window.htm
0
 
LVL 13

Assisted Solution

by:cLFlaVA
cLFlaVA earned 250 total points
ID: 12050301
Something like this:

<script language="javascript">
function highlightRow(row) {
    unhighlightRows();
    row.style.background = 'gray';
}

function unhighlightRows() {
    for (var i=1; i<=3; i++) {
        document.getElementById("row" + i.toString()).style.background = 'red';
    }
}
</script>

<table>
<tr name="row1" onclick="highlightRow(this);" style="background: gray"><td>r1c1</td><td>r1c1</td></tr>
<tr name="row2" onclick="highlightRow(this);" style="background-color: gray"><td>r2c1</td><td>r2c1</td></tr>
<tr name="row3" onclick="highlightRow(this);" style="background-color: gray"><td>r3c1</td><td>r3c1</td></tr>
</table>
0
 
LVL 1

Author Comment

by:maunded
ID: 12050346
Cool...heres something I forgot to mention..whoops.
Each alternate row is a different color.  This is done using a PHP script which changes the tr bgcolor property
Is there any way to pass that back to the unhighlightRows function?
0
 
LVL 6

Accepted Solution

by:
ren_b earned 250 total points
ID: 12050846
<html>
<head>
<script type="text/javascript">
var lastrow, lastbg;
function highlightRow(row){
  if(lastrow != null)
    lastrow.style.backgroundColor = lastbg;
  lastbg = row.style.backgroundColor;
  row.style.backgroundColor = "red";
  lastrow = row;
}
</script>
</head>
<body>
<table>
<tr name="row1" onclick="highlightRow(this);" style="background: green"><td>r1c1</td><td>r1c1</td></tr>
<tr name="row2" onclick="highlightRow(this);" style="background-color: blue"><td>r2c1</td><td>r2c1</td></tr>
<tr name="row3" onclick="highlightRow(this);" style="background-color: purple"><td>r3c1</td><td>r3c1</td></tr>
</table>
</body>
</html>
0
 
LVL 1

Author Comment

by:maunded
ID: 12051361
Excellent work gentlemen!!
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question