Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

48 users online



javascript checkbox to colo(u)r cell

javascript checkbox to colo(u)r cell

Currently viewing this thread: 1 (0 members and 1 guests)


asmega

asmega

Status: Offline!

javascript checkbox to colo(u)r cell

ok heres the problem - been looking at a html book which has some java script in and cant get my head round it and after 2 days my head is still hurting and still cant get this to work

i want a checkbox to color the table cell it is in - for example when it is checked the cell shud go red and when not checked the cell shud be green. note the checkbox is in the cell i want colored.

well i can get this to work but however also i wud like the cell to be colored upon loading the document. so upon loading if box is checked then cell shud be red if not then green. to say whether this box is checked or not php will be used this will simply send to the input/checkbox tag with 'checked' option printed or not.

does this make sense?

___________________

No one will ever know the meaning of life.

fredmv

fredmv

Status: Offline!

Try this:

Code:

[size=1]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<script type="text/javascript">
//<![CDATA[
onload = function()
{
var c = document.getElementsByTagName('input')[0];
c.parentNode.parentNode.style.backgroundColor = (c.checked) ? '#f00' : '#090';
}
//]]>
</script>
</head>
<body>
<table summary="" style="width: 100%;">
<tr>
<td>
<input type="checkbox" onclick="parentNode.parentNode.style.backgroundColor = (checked) ? '#f00' : '#090';" />
</td>
</tr>
</table>
</body>
</html>[/size]

___________________

http://home.comcast.net/~fredv4/tf/firefox.gif

Sykil

Sykil

Neversidian
Status: Offline!

You're such a brain Fred Smile I never could get the conditional operator. (i believe that is what it is.)

___________________

http://imagegen.last.fm/artist/artists/Sykil.gif
Free-Speed Nation

asmega

asmega

Status: Offline!

isnt that just a 'if' statement?

___________________

No one will ever know the meaning of life.

fredmv

fredmv

Status: Offline!
Quote:

Originally posted by .sykil
I never could get the conditional operator. (i believe that is what it is.)


It looks slightly complex at first but once you see an example of it's usage and understand how it works it's quite simple.

Quote:

Originally posted by asmega
isnt that just a 'if' statement?


It functions similar to an if statement however it uses less syntax and makes more sense to use when you only have one statement you want to execute for each different result of the test as opposed to using an if/else block.

___________________

http://home.comcast.net/~fredv4/tf/firefox.gif

asmega

asmega

Status: Offline!

how do i get this to work for 5 checkboxes for 5 different cells for 5 different tables?

___________________

No one will ever know the meaning of life.

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0082 seconds.