Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-13
5
Medium Priority
?
272 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
[X]
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
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 1000 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 1000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

610 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