This is a discussion on how to highlight cell within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi all, I have a table with 12 cols and 10 rows. When a user clicks on a table cell; ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
I have a table with 12 cols and 10 rows. When a user clicks on a table cell; the page is refreshed and displays some data below the table dependant on whichever cell was selected. I would like to make it so that whichever cell was clicked; the background color is changed - so that when the user sees the data, (s)he can tell which cell it relates to. Does anyone know of a clever way to do this ? I'm afraid my creativity is running a bit dry on this one as the only working way i could come up with so far is to have an if statement before each table cell is created, which is long winded. kind regards T |
|
|||
|
toffee wrote:
> Hi all, > > I have a table with 12 cols and 10 rows. When a user clicks on a table cell; > the page is refreshed and displays some data below the table dependant on > whichever cell was selected. > I would like to make it so that whichever cell was clicked; the background > color is changed - so that when the user sees the data, (s)he can tell which > cell it relates to. > > Does anyone know of a clever way to do this ? > I'm afraid my creativity is running a bit dry on this one as the only > working way i could come up with so far is to have an if statement before > each table cell is created, which is long winded. > > kind regards > > T Long winded indeed. The only other option I can think of at the moment is keeping an array for each cell as X,Y coordinates, and the value of the array element would be a string like 'style="background-color:#CCCCCC;"'. Then just reference array location for each cell and output the contents. If it is empty, fine, but if you assign a string like that, the color will change. Both solutions require you to put code at each cell though... I've never figured out any way around it. Ex: <? $cellStyles = array(); $cellStyles[1][0] = 'style="background-color:#CCCCCC;"'; ?> <table> <tr> <td <?=$cellStyles[0][0]?>>a</td> <td <?=$cellStyles[1][0]?>>b</td> </tr> <tr> <td <?=$cellStyles[0][1]?>>c</td> <td <?=$cellStyles[1][1]?>>d</td> </tr> </table> |
|
|||
|
Hmm toffee <toffee@toffee.com> wrote:
> Does anyone know of a clever way to do this ? you can use css to show color on clicked cell - bkg color or bkg img but you will have to remeber in script what cell was clicked orter solution make make href and set visited option on your bkg color then you no need script -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl 2be || !2be $this => mysql_query(); |
|
|||
|
| Both solutions require you to put code at each cell though...
| I've never figured out any way around it. | | Ex: | <? | $cellStyles = array(); | $cellStyles[1][0] = 'style="background-color:#CCCCCC;"'; | ?> | | <table> | <tr> | <td <?=$cellStyles[0][0]?>>a</td> | <td <?=$cellStyles[1][0]?>>b</td> | </tr> | <tr> | <td <?=$cellStyles[0][1]?>>c</td> | <td <?=$cellStyles[1][1]?>>d</td> | </tr> | </table> perhaps this may be easier (if i understood you correctly): <html> <style type="text/css"> td { background-color : white; cursor : pointer; width : 50px; } </style> <script type="text/javascript"> var currentCell; function colorMe(el) { if (!el){ return; } if (!el.style){ return; } if (currentCell){ currentCell.style.backgroundColor = ''; } currentCell = el; currentCell.style.backgroundColor = '#CCCCCC'; } </script> <body> <table> <tr> <td onclick="colorMe(this);">a</td> <td onclick="colorMe(this);">b</td> </tr> <tr> <td onclick="colorMe(this);">c</td> <td onclick="colorMe(this);">d</td> </tr> </table> <body> <html> |
|
|||
|
Hmm Steve <no.one@example.com> wrote:
> perhaps this may be easier (if i understood you correctly): nope :) he wrote about refresh, and what if some1 block js? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl 2be || !2be $this => mysql_query(); |
|
|||
|
".:[ ikciu ]:." <no@mail.com> wrote in message news:eh5qgm$3to$1@news.dialog.net.pl... | Hmm Steve <no.one@example.com> wrote: | > perhaps this may be easier (if i understood you correctly): | | nope :) he wrote about refresh, and what if some1 block js? if you're going to ridicule me again, but in this thread now, i suggest that you learn to COMPREHEND english!!! unless you want me to embarrass you again. in case you missed it, the OP spoke of MANY things...but THIS is his question: <quote> I would like to make it so that whichever cell was clicked; the background color is changed </quote> so yes, my example does EXACTLY that...fucking moron! |
|
|||
|
thanks everyone for the suggestions and I didnt mean to start an argument
:-/ Steve - apologies for not making it clearer, but when a user clicks on a cell the page is indeed refreshed; i just wanted to be able to show which cell caused the refresh by highlighting it. kind regards T "Steve" <no.one@example.com> wrote in message news:AcuZg.532$_z4.142@newsfe07.lga... > > ".:[ ikciu ]:." <no@mail.com> wrote in message > news:eh5qgm$3to$1@news.dialog.net.pl... > | Hmm Steve <no.one@example.com> wrote: > | > perhaps this may be easier (if i understood you correctly): > | > | nope :) he wrote about refresh, and what if some1 block js? > > if you're going to ridicule me again, but in this thread now, i suggest that > you learn to COMPREHEND english!!! unless you want me to embarrass you > again. in case you missed it, the OP spoke of MANY things...but THIS is his > question: > > <quote> > I would like to make it so that whichever cell was clicked; the background > color is changed > </quote> > > so yes, my example does EXACTLY that...fucking moron! > > |
|
|||
|
Don't worry about those 2 arguing. They seem to be like the Odd Couple.
I've watched them bicker through 2 threads already within the past 24 hours. Wish they could just all get along...or take it outside...or something. As long as you get your solution, this ng proves its worth. toffee wrote: > thanks everyone for the suggestions and I didnt mean to start an argument > :-/ > > Steve - apologies for not making it clearer, but when a user clicks on a > cell the page is indeed refreshed; i just wanted to be able to show which > cell caused the refresh by highlighting it. > > kind regards > > T > > "Steve" <no.one@example.com> wrote in message > news:AcuZg.532$_z4.142@newsfe07.lga... > >> ".:[ ikciu ]:." <no@mail.com> wrote in message >> news:eh5qgm$3to$1@news.dialog.net.pl... >> | Hmm Steve <no.one@example.com> wrote: >> | > perhaps this may be easier (if i understood you correctly): >> | >> | nope :) he wrote about refresh, and what if some1 block js? >> >> if you're going to ridicule me again, but in this thread now, i suggest >> > that > >> you learn to COMPREHEND english!!! unless you want me to embarrass you >> again. in case you missed it, the OP spoke of MANY things...but THIS is >> > his > >> question: >> >> <quote> >> I would like to make it so that whichever cell was clicked; the background >> color is changed >> </quote> >> >> so yes, my example does EXACTLY that...fucking moron! >> >> >> > > > |
|
|||
|
"toffee" <toffee@toffee.com> wrote in message news:eh65mo$6g2$1@news.freedom2surf.net... | thanks everyone for the suggestions and I didnt mean to start an argument | :-/ | | Steve - apologies for not making it clearer, but when a user clicks on a | cell the page is indeed refreshed; i just wanted to be able to show which | cell caused the refresh by highlighting it. | | kind regards | | T very good. i actually posted that so you'd flesh out how you wanted the refresh to run. one way is to use javascript and populate all the data needed for all the cells and just hide that data in a div in the html...getting it via js would allow you one trip to the server without the refresh. as it is, i see you intend not to use js. the solution is fairly simple...i'll work up a quick example and post it here. cheers |
|
|||
|
"Breklin" <breklin@sbcglobal.net> wrote in message news:1yxZg.16089$e66.5994@newssvr13.news.prodigy.c om... | Don't worry about those 2 arguing. They seem to be like the Odd Couple. | I've watched them bicker through 2 threads already within the past 24 | hours. Wish they could just all get along...or take it outside...or | something. lol. it does seem that way, doesn't it. i've got him plonked so i won't see further posts. l8r |