Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,378 members, 7,998,799 topics. Date: Sunday, 10 November 2024 at 07:59 AM

Quick Question - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Quick Question (656 Views)

A Quick Question For Bloggers. / Quick Question About GTB-TOKEN / Quick Question (2) (3) (4)

(1) (Reply) (Go Down)

Quick Question by yawatide(f): 5:55am On Feb 16, 2009
I have a table that prints out say, a bunch of numbers via a loop. I am using PHP. The output looks like so:


<table>
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
</table>

Now, I want to be able to, upon hover in a particular cell, make the background of each individual cell change color. Of course this would be too easy if the colors were the same. So to make this juicier, I want each cell to have a differnent background color, upon hover. As a hint, that means each cell needs to have a unique ID so that I can access it via the DOM. I could give all of them a class, but I would still need to use document.getElementById() to access the unique ID before accessing className().

Question:
How do I give each TD it's own unique ID? Note: I am not asking for the onHover code. That is just to make you think. I just need the solution to my actual question: how to give each cell it's unique ID.

I await responses smiley
Re: Quick Question by Nobody: 10:50pm On Feb 16, 2009
You can have the answer in pure javascript or via javascript generated with php. But for some reasons, i am not going to write this code.
Re: Quick Question by yawatide(f): 11:47am On Feb 17, 2009
Why? You scared? tongue

Drop code make bobos learn e jo cool
Re: Quick Question by kehers(m): 12:14pm On Feb 17, 2009
Depends on au u r populating the table.
If from a db,u can declare a counter variable this way

$x = 1;
while(. . .){
echo '<td id="cell'.$x.'" onmouseover="this.className=\'anodaclass\'" onmouseout="this.className=\'defaultclass\'">. . .';
//. . .
$x++;
}
By the way i hope that was wat u mean.
Re: Quick Question by yawatide(f): 12:42pm On Feb 17, 2009
Yes Kehers,

You are correct cool

By the way, I did say that the javascript part was unnecessary and I didn't say where the data was coming from (just that it was generated by a loop) but I won't use that to take away from your answer wink

I will try to come up with more questions in the future.
Re: Quick Question by Nobody: 6:13pm On Feb 17, 2009
I have done something like that with javascript some years ago, very clean and unobtrusive javascript.
So seriously this does not challenge me, but so dat dem no go talk se i get mouth for nothing, if someone drops a working solution, i will drop it.

(1) (Reply)

Big-bang Offer / Testers Required For A New Portal / To Employ A Good Web Designer.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.