views:

30

answers:

2

I have a list of categories on my webpage. They are stored on mysql and each category has an id number next to it.

The categories are in divs that when selected change color and whatnot, and when not selected, another color. Only one can be selected at a time.

I am trying to figure out how to tell the webpage, which cat has been selected, and in turn, it will make the selected cat take on the selected style traits

thank you

+1  A: 

Sounds pretty simple to me. Why don't you embed a GET variable into the link of the category?

<a href="www.mypage.com?category=This_Category">This Category</a>

then, on reload:

if(!empty($_GET['category'])) { $selectedCat = $_GET['category']; }
johnnietheblack
I was under the impression the OP wanted a client side solution... perhaps I was wrong.. :(
Christian
no worries...still a good solution.
johnnietheblack
Maybe I'm not reading this thing right at all. The question says "how to tell the webpage which cat has been selected", but it seems that your solution would be more for how to tell the server which page has been selected. Granted, if the server knows, and the page is being loaded, the server can output which category was selected. But this doesn't seem to address the somewhat vauge issue.
Anthony
A: 

Make sure each div has its own unique id, using javascript add an onclick event to each div, create a function called colourChange() to fire when clicked on (or whatever you want to call it). Then, you can have a variable set to the id of the field that is currently highlighted, if that id is the same as the field just clicked, do nothing, or remove the class / highlighting and add it to the new one.

JQuery will make this super easy for you.

EDIT: Perhaps I misunderstood, I was under the impression you wanted a client side solution, please disregard this if you wanted PHP to handle it on page loads.

Christian
i think he was looking for a php answer though?
johnnietheblack
Yeah got that on the second read. :)
Christian
Christian, maybe you can help me understand how this is a server-side question, since you understood that your client-side solution is not better. I've read the question 3 times now, and I can't figure out a)why someone would want to make this server-side and b) what exactly the server is doing in the scenario.
Anthony
The tags gave it away for me. I thought client side straight away until I saw them.
Christian