Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-09-13
5
263 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select case on click 3 19
check a checkbox of a checkboxes group in bootstrap 2 40
html border input line 7 13
Button on Table, name table1 not working 4 20
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

790 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