Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now