User-changeable colours

T

Tim Green

Hi,

I have a simple table with two cells.

I'd like to present another two tables with 4 coloured cells (say, red,
blue, green and yellow), and invite the user to click on a colour in one
table to change the backround of the first cell, and on a colour in the
second table to change the background of the second cell.

Does anyone know if there's a reasonably simple way to do this? Or can
someone show me a sample?

Thanks for any hellp.
 
J

Jc

Tim said:
I have a simple table with two cells.

I'd like to present another two tables with 4 coloured cells (say, red,
blue, green and yellow), and invite the user to click on a colour in one
table to change the backround of the first cell, and on a colour in the
second table to change the background of the second cell.

Does anyone know if there's a reasonably simple way to do this? Or can
someone show me a sample?

This can be done using javascript. You may want to read a tutorial on
javascript and the Document Object Model (DOM) that javascript can
access in a browser environment. Here's a link to a tutorial:
http://www.w3schools.com/dhtml/default.asp

You will eventually need to use the onclick event, and a way to access
the target table, one of which is the document.getElementById method.
You could then navigate the DOM to the desired cell and set the color
using the style object (CSS).

The FAQ for this group has links to other references which may also be
of use: http://www.jibbering.com/faq/.
 
R

Richard Cornford

Tim said:
I have a simple table with two cells.

I'd like to present another two tables with 4 coloured cells (say,
red, blue, green and yellow), and invite the user to click on a
colour in one table to change the backround of the first cell, and on
a colour in the second table to change the background of the second
cell.

That is such an utterly pointless thing to do that it sounds like a
school/college assignment. Is it?

Richard.
 
T

Tim Green

For JC: Thank you.

For Richard: No, it's not a school assignment. What I need to do is more
complex and is a real-world application. It seemed pointless to describe it
all, so I took the essence of one problem and created a simple,
understandable example. Solve the simple example, and I've solved my
colour-change problem.

Tim
 
T

Tim Green

Hi Danny,

I read a few of the references (before seeing your note), and experimented a
little. Took me all Sunday, but I got exactly what I was looking for. And
used the same technique you describe. I also learned I could pass arguments
to the function I created, so I didn't have to create all kinds of extra
code.

Thanks. Wish I had seen your note first... :)

- Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top