|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a table which I want to make so that any line that currently has the mouse over gets a specific colour, but since I use multiple colours for my rows, I'd want it restored, any suggestions on how to do this? I'm having a little hassle figuring this out (maybe I'm just tired =P)
<TR BGCOLOR="..." onMouseOver="trMouseOver(this);" onMouseOut="trMouseOut(this);"> ... And the script var lastColor; function trMouseOver(obj) { lastColor = obj.style.backgroundColor; obj.style.backgroundColor = 'white'; } function trMouseOut(obj) { obj.style.backgroundColor = lastColor; } Ol |
|
#2
|
|||
|
|||
|
As a PS...
One problem with the particular method I've included, is that for a table with a LOT of rows it adds a LOT to the document. I was hoping their might be a better way to do it The tables are generated from a database using PHP, so if there is a simpler way to do it which is just tedious codewise (e.g. giving every TR an ID or something) that's fine. |
|
#3
|
|||
|
|||
|
Your code to swap the colours works fine in IE5?
An alternative to rewriting the onmouse.. bits could be to send in the data from php or whatever to an array in javascript and just make a loop to create the table based on your array.. umm heres a basic example to what i'm trying to say... <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> <body> <script> mktab(); </script> </body> [/code] script to highlight rows: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> var x; function over(obj) { x = obj.style.backgroundColor; obj.style.backgroundColor = 'white'; } function out(obj) { obj.style.backgroundColor = x; } [/code] script to mk table: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> function mktab() { _w('<table border=1>'); for (key in row_array) _w('<tr onmouseover="over(this);" onmouseout="out(this);" bgcolor=' + col_array[key] + '><td>' + row_array[key] + '</td>'); _w('</table>'); } function _w(y) { document.writeln(y); } [/code] and finally send some data from php into a couple of arrays to populate table & give colours to make rows or something eg: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> var row_array = new Array('one','two','three'); var col_array = new Array('red','green','blue'); [/code] hope that helps :] ravikesh |
|
#4
|
|||
|
|||
|
hi Oliver, there is a way to do this using IDs and CLASS with CSS... here is an example below:
<HTML> <HEAD> <TITLE>ack</TITLE> <style> .COLD { background-Color:blue; color:red; } .HOT { background-Color:red; color:blue; } </style> </HEAD> <BODY bgcolor="000000"> <table width="50%" border="0" cellspacing="0" cellpadding="0"> <tr> <td ID="TD1" CLASS="COLD" onmouseover="TD1.className='HOT'" onmouseout="TD1.className='COLD'">cell1</td> <td ID="TD2" CLASS="COLD" onmouseover="TD2.className='HOT'" onmouseout="TD2.className='COLD'">cell2</td> <td ID="TD3" CLASS="COLD" onmouseover="TD3.className='HOT'" onmouseout="TD3.className='COLD'">cell3</td> <td ID="TD4" CLASS="COLD" onmouseover="TD4.className='HOT'" onmouseout="TD4.className='COLD'">cell4</td> </tr> </table> </BODY> </HTML> ya I know it is still kinda wordy to write for each element but it does allow you to change more than one style at a time.. also, if you are using php to generate the table then when you are running off the rows from your query or whatever you will need to create and append your counter's variable to the ID of the element. TD+1, TD+2 etc.. hope this helps! |
|
#5
|
|||
|
|||
|
whoops an even easier way to do this would be to bypass the IDs completely and use:
<td CLASS="COLD" onmouseover="this.className='HOT'" onmouseout="this.className='COLD'">text</td> but you could still use IDs to affect different elements on the page etc.. |
|
#6
|
|||
|
|||
|
Grr - Am I right in thinking that Netscape does not support 'onMouseOver' on anything except anchors?
Oliver |
|
#7
|
|||
|
|||
|
I am thinking you're right. One thing you can do to get around this is to stretch a small transparent gif over your table and then make an image map out of it. This will have the effect of making the area covered by the anchor tags large enough to cover the area of your table cells. Take a look at netscape's own homepage and you'll see that they use this workaround too.
|
|
#8
|
|||
|
|||
|
Well, I just found this script on the web, which seems to do what ya all are asking: http://www.dynamicdrive.com/dynamic...hlighttable.htm
Seems to be for IE only though... |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > table row background colour |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|