473,388 Members | 902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

change background color on hover or select

I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in that row
is selected?
Poko
Sep 25 '05 #1
13 12472
Gary said the following on 9/25/2005 3:18 AM:
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in that row
is selected?


Yes, it is very possible and quite simple actually. Search the archives,
give it your best try, and post back with some code and/or a URL to your
efforts. Or, did you expect someone to write the entire thing from scratch?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 25 '05 #2
Randy Webb wrote:
Gary said the following on 9/25/2005 3:18 AM:
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in
that row is selected?


Yes, it is very possible and quite simple actually. Search the
archives, give it your best try, and post back with some code and/or
a URL to your efforts. Or, did you expect someone to write the entire
thing from scratch?


:) Point taken, thank you for your response Randy
poko
Sep 25 '05 #3
ASM
Gary a écrit :
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in that row
is selected?
Poko


No, you have a form containing a table
(table can't contain a form)
(table can contain elements of a form)

see that :
http://perso.wanadoo.fr/stephane.mor...ht_rows_en.htm
<html><form><table border=1 cellspacing=0>
<tr>
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
</table></form>
<script type="text/javascript">
function highLght(chckbox) {
var rw = chckbox.parentNode.parentNode;
rw.className = (chckbox.checked)? 'backCol' : '';
}
</script>
<style type="text/css">
..backCol { background-color: yellow }
</style>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Sep 25 '05 #4
ASM
Randy Webb a écrit :
Or, did you expect someone to write the entire thing from scratch?


Sorry ...

--
Stephane Moriaux et son [moins] vieux Mac
Sep 25 '05 #5
ASM wrote:
Gary a écrit :
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in
that row is selected?
Poko
No, you have a form containing a table
(table can't contain a form)
(table can contain elements of a form)


:) u da man!
But of course you are right.

see that :
http://perso.wanadoo.fr/stephane.mor...ht_rows_en.htm merci beaucoup ASM, I'm afraid to say its slightly above my abilities but it
gives me something to work with :)
poko

<html><form><table border=1 cellspacing=0>
<tr>
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
</table></form>
<script type="text/javascript">
function highLght(chckbox) {
var rw = chckbox.parentNode.parentNode;
rw.className = (chckbox.checked)? 'backCol' : '';
}
</script>
<style type="text/css">
.backCol { background-color: yellow }
</style>
</html>

Sep 25 '05 #6
ASM wrote on 25 sep 2005 in comp.lang.javascript:
Gary a écrit :
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in
that row is selected?
Poko
No, you have a form containing a table
(table can't contain a form)
(table can contain elements of a form)

see that :
http://perso.wanadoo.fr/stephane.mor...hlight_rows_en.
htm
<html><form><table border=1 cellspacing=0>

[..] </html>


This will hover and will be clickable along the whole <tr>:

<html>

<style type="text/css">
..backCol { background-color:yellow;}
..hoverbackCol { background-color:blue;color:white;}
</style>

<script type="text/javascript">

function ifhover(x,istrue) {
if (istrue) bgsave=x.className
x.className = (istrue)?'hoverbackCol':
(x.firstChild.firstChild.checked)? 'backCol' : '';
}

function clickhighLght(x) {
x.firstChild.firstChild.checked =
!x.firstChild.firstChild.checked;
x.className =
(x.firstChild.firstChild.checked)? 'backCol' : '';
}

function highLght(chckbox) {
clickhighLght(chckbox.parentNode.parentNode);
}
</script>

<form>
<table border=1 cellspacing=0>

<tr onclick="clickhighLght(this)"
onmouseover="ifhover(this,true)"
onmouseout="ifhover(this, false)">
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>

<tr onclick="clickhighLght(this)"
onmouseover="ifhover(this,true)"
onmouseout="ifhover(this, false)">
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>

</table>
</form>
</html>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 25 '05 #7
Evertjan. wrote:
ASM wrote on 25 sep 2005 in comp.lang.javascript:
Gary a écrit :
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color
on mouseover or hover and make it stay that color when the checkbox
in that row is selected?
Poko


No, you have a form containing a table
(table can't contain a form)
(table can contain elements of a form)

see that :
http://perso.wanadoo.fr/stephane.mor...hlight_rows_en.
htm
<html><form><table border=1 cellspacing=0>

[..]
</html>


This will hover and will be clickable along the whole <tr>:

<html>

<style type="text/css">
.backCol { background-color:yellow;}
.hoverbackCol { background-color:blue;color:white;}
</style>

<script type="text/javascript">

function ifhover(x,istrue) {
if (istrue) bgsave=x.className
x.className = (istrue)?'hoverbackCol':
(x.firstChild.firstChild.checked)? 'backCol' : '';
}

function clickhighLght(x) {
x.firstChild.firstChild.checked =
!x.firstChild.firstChild.checked;
x.className =
(x.firstChild.firstChild.checked)? 'backCol' : '';
}

function highLght(chckbox) {
clickhighLght(chckbox.parentNode.parentNode);
}
</script>

<form>
<table border=1 cellspacing=0>

<tr onclick="clickhighLght(this)"
onmouseover="ifhover(this,true)"
onmouseout="ifhover(this, false)">
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>

<tr onclick="clickhighLght(this)"
onmouseover="ifhover(this,true)"
onmouseout="ifhover(this, false)">
<td>
<input type=checkbox onclick="highLght(this)">
</td>
<td>blah</td><td>blah</td><td>blah</td>
</tr>

</table>
</form>
</html>


Evertjan!
thats exactly what I was hoping for......thank you!
poko
Sep 25 '05 #8
ASM wrote in message news:43***********************@news.wanadoo.fr...
Gary a écrit :
I have a table with a form consisting of several checkboxes and I'm
wondering if its possible to change the table row background color on
mouseover or hover and make it stay that color when the checkbox in that row
is selected?
Poko
see that :
http://perso.wanadoo.fr/stephane.mor...ht_rows_en.htm
A very long long time ago (about 4 years) I managed to put together the
following "tables" and javascript (sorry about all the junk in there):
http://www.geocities.com/peg_seti/gr...tm#country-tbl
I have no idea on what browsers it worked, but it still does in FF ;-)
The idea was to be able to move the mouse over a row in any of the last
four tables and it would highlight the respective row in the other three.

I did validate it once , but as I said, that was eons of years ago.
So ignore the align="absbottom" errors if you /have/ to validate it ;-)
Thank FrontPage of Micro$oft for that...

BTW, you say
No, you have a form containing a table
(table can't contain a form)
actually it can; not directly in the <table> tag but in <TD> and <TH>

<!ENTITY % block
"P | %heading; | %list; | %preformatted; | DL | DIV | CENTER |
NOSCRIPT | NOFRAMES | BLOCKQUOTE | FORM | ISINDEX | HR |
TABLE | FIELDSET | ADDRESS">
---> ^^^^^ ^^^^

<!ENTITY % flow "%block; | %inline;">
---> ^^^^^^^
<!ELEMENT TABLE - -
(CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>

<!ELEMENT (TH|TD) - O (%flow;)* -- table header cell, table data cell-->
---> ^^^^^^
(table can contain elements of a form)


I have both in http://www.geocities.com/peg_seti

<table>
<tr>
<td>
<form ...>
<table>
<tr>
<td>
<input ...>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

Sep 25 '05 #9
ASM
Robi a écrit :
ASM wrote in message news:43***********************@news.wanadoo.fr...
see that :
http://perso.wanadoo.fr/stephane.mor...ht_rows_en.htm

A very long long time ago (about 4 years)


Do you mean I did nothing invent ?
You're right.
Sometimes, I try some idea found here or there
and I keep it to show to others if I think it can be of some interest.
(any copyright, even not my name most of the time)
I managed to put together the
following "tables" and javascript (sorry about all the junk in there):
http://www.geocities.com/peg_seti/gr...tm#country-tbl
I have no idea on what browsers it worked, but it still does in FF ;-)
Oh, I have also a little demo about that, not so elaborated than yours.
The most difficulty is to crutch IE
The idea was to be able to move the mouse over a row in any of the last
four tables and it would highlight the respective row in the other three.
For the moment I'm fighting with appendChild in a table a cloneNoded row.
That's work fine with FF, Opera and others except ... IE (of course)
I have yet to do a simplier test before coming to ask here what is wrong.
I did validate it once
Hope you will not try with my little demos ...
I didn't it.
No, you have a form containing a table
(table can't contain a form)

actually it can; not directly in the <table> tag but in <TD> and <TH>


That's what I wanted to say, in fact the form is in a td
by chance a td is part of a table :-)
(because certainly you use a table as structural tool)

By end and ... finaly the form contains a table
turned this way, I could too say the table below contains a table :-)
<table>
<tr>
<td>
<form ...>
<table>
<tr>
<td>
<input ...>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 25 '05 #10
ASM wrote:
[...]

For the moment I'm fighting with appendChild in a table a cloneNoded row.
That's work fine with FF, Opera and others except ... IE (of course)
I have yet to do a simplier test before coming to ask here what is wrong.


Remember that when encountering a table, browsers will insert a tbody
element into the DOM even if there isn't one in the source HTML (they
are mandatory elements but the tags are optional).

A common problem is attempting to append a new row to a table element
when you should append to a tbody element. Other browsers will tolerate
it and add the row to the tbody anyway, but not IE.

e.g. if 'el' is a reference to a table:

var aRow = el.rows[0].cloneNode(true);
el.appendChild(aRow);

will not work in IE. But:

var aRow = el.rows[0].cloneNode(true);
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentNode.insertBefore(aRow, lastRow.nextSibling);

will work (and in others too) because the parent of the lastRow is a
tbody, not a table.

There is a sample below. Of course I could have just used a tbody
element instead of the table when climbing the tree, this is just a demo.

<script type="text/javascript">

function cloneRow( el )
{
// Get the table - should use tbody but this is just for show
while (el.parentNode && 'table' != el.nodeName.toLowerCase()){
el = el.parentNode;
}
var aRow = el.rows[0].cloneNode(true);

// The next line won't work in IE
// el.appendChild(aRow);

// But these will
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentNode.insertBefore(aRow, lastRow.nextSibling);

}

</script>

<table border="1">
<tr>
<td onclick="cloneRow(this)">Click me</td>
</tr>
</table>

[...]

--
Rob
Sep 25 '05 #11
ASM
RobG a écrit :
ASM wrote:
[...]

For the moment I'm fighting with appendChild in a table a cloneNoded row.
That's work fine with FF, Opera and others except ... IE (of course)
I have yet to do a simplier test before coming to ask here what is wrong.

Remember that when encountering a table, browsers will insert a tbody
element into the DOM even if there isn't one in the source HTML (they
are mandatory elements but the tags are optional).

A common problem is attempting to append a new row to a table element
when you should append to a tbody element. Other browsers will tolerate
it and add the row to the tbody anyway, but not IE.


No, no, I appendChild in a tbody
But, perhaps my row is too heavy for this poor IE (my IE5.2 Mac ...)
with css and IE's roll-over +
image (with onclick) +
input with onchange
etc

way I do :
I have an undisplayed table with one row
I have an other table of x rows (thead, tbody, tfoot)
each row of each tbody of both tables are same (except a td text)

var rw = document.getElementById('refRow').cloneNode(true);
give a new id to the clone
var tb = document.getElementById('tBodyTarget');
tb.appendchild(rw);
original row being not undisplayed
I have not to display in IE understanding : tableRow

IE is lost with width of cols (1st col width becomes initial table width)
IE forget all events (an alert showes it)

I did try with M$ function : insertRow()
without succes because that would only create a new empty row
(and I'm not sure that works with IE Mac)
e.g. if 'el' is a reference to a table:

var aRow = el.rows[0].cloneNode(true);
el.appendChild(aRow);

will not work in IE. But:

var aRow = el.rows[0].cloneNode(true);
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentNode.insertBefore(aRow, lastRow.nextSibling);
Perhaps could I try that
(but I have a tfoot ... ?)
will work (and in others too) because the parent of the lastRow is a
tbody, not a table.

There is a sample below. Of course I could have just used a tbody
element instead of the table when climbing the tree, this is just a demo.
keep it here for my archives (and later try)
<script type="text/javascript">

function cloneRow( el )
{
// Get the table - should use tbody but this is just for show
while (el.parentNode && 'table' != el.nodeName.toLowerCase()){
el = el.parentNode;
}
var aRow = el.rows[0].cloneNode(true);

// The next line won't work in IE
// el.appendChild(aRow);

// But these will
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentNode.insertBefore(aRow, lastRow.nextSibling);

}

</script>

<table border="1">
<tr>
<td onclick="cloneRow(this)">Click me</td>
</tr>
</table>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #12
ASM wrote:
RobG a écrit :
ASM wrote:
[...]

For the moment I'm fighting with appendChild in a table a cloneNoded
row.
That's work fine with FF, Opera and others except ... IE (of course)
I have yet to do a simplier test before coming to ask here what is
wrong.


Remember that when encountering a table, browsers will insert a tbody
element into the DOM even if there isn't one in the source HTML (they
are mandatory elements but the tags are optional).

A common problem is attempting to append a new row to a table element
when you should append to a tbody element. Other browsers will
tolerate it and add the row to the tbody anyway, but not IE.

No, no, I appendChild in a tbody
But, perhaps my row is too heavy for this poor IE (my IE5.2 Mac ...)


Hmm, it was a long shot. I'll have a play with IE Mac later (actually
much later... say +7hrs from now).

[...]
--
Rob
Sep 26 '05 #13
ASM
RobG a écrit :
ASM wrote:
RobG a écrit :
ASM wrote:
[...]
For the moment I'm fighting with appendChild in a table a cloneNoded
row.
That's work fine with FF, Opera and others except ... IE (of course)

A common problem is attempting to append a new row to a table element
when you should append to a tbody element. Other browsers will
tolerate it and add the row to the tbody anyway, but not IE.


No, no, I appendChild in a tbody
But, perhaps my row is too heavy for this poor IE (my IE5.2 Mac ...)


Hmm, it was a long shot. I'll have a play with IE Mac later (actually
much later... say +7hrs from now).


if ...
http//perso.wanadoo.fr/stephane.moriaux/truc/clone_row.htm
--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David T-G | last post by:
Hi! Please be gentle; I'm new to ciwas and CSS in general, and know little to no javascript (but that might win me points here ;-) I have nine 'tab' images, with corresponding high-background...
2
by: carramba | last post by:
Hi! is it possible to change "selector" color in drop-down list? <select name="select" style="background-color: #ff0000"> <option style="background-color: #ff0000" value="1">Cony</option>...
1
by: nick | last post by:
I have the following code: <style> #item1 { DISPLAY: block; BACKGROUND: url(ProjMenuImgs/ProjBtn.gif) no-repeat 0px 0px; WIDTH: 87px; HEIGHT: 94px; } #item1:hover { background-position: 0...
10
by: Richard | last post by:
The style sheet shown below is from the suckerfish vertical menu. http://www.htmldog.com/articles/suckerfish/dropdowns/example/vertical.html I've added in a few minor changes to color code the...
11
by: Yeah | last post by:
I have a multiple choice quiz where I would like to use CSS to change the color of the answers upon clicking them. I would like to present the right and wrong answers up front, rather than direct...
3
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make...
2
by: chris_culley | last post by:
Hi there, I've got a gif with (highly) irregular shapes (lots of jigsaw pieces) that I want to map so that each piece is a link... The pieces are currently just a frame drawing, but as they...
1
by: roN | last post by:
Hi, I have a table in which I would like to change the background image onMouseOver. I implemented it with CSS but IE doesn't support hovers on tables, so I'd need to go via JS for IE. Can...
5
by: studentofknowledge | last post by:
hi guys im new to javascript and need some guidence please.. im trying to display a 400x400 pixel coloured area in the middle of a webpage that stays in the middle with a browser window resize....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.