Log in

View Full Version : Switching Content using a menu



SafferBoy
07-15-2010, 12:53 PM
Hi,

I have 3 tables that are generated using PHP to fetch information from a db.

Instead of displaying the 3 tables below each other, I would like to display each using a simple menu in a left nav bar that "dynamically" displays the tables in a right content area, when the respective table name is selected from the menu.

Any ideas on the best way to do this? The tables are quite large, so I would want to prevent querying the db each time... but I guess that is an option.

Was thinking of using DIV visible, but I'm not sure if it will always display at the top.

Any ideas greatly appreciated.

Thanks!

djr33
07-16-2010, 02:15 AM
A dropdown menu could switch divs by hiding one and making another visible, yes. That's a good way.

Alternatively you could use Ajax, but that would query the database every time.

I think using the hiding/showing method is a good idea.

document.getElementById('mydiv').style.display = 'none';
document.getElementById('mydiv').style.display = 'block';

Those two lines will invert visibility. Just apply them as a function to show the right div-- hide the others and show the desired one. Make that the onChange for the dropdown.