true2self Posted November 12, 2008 Share Posted November 12, 2008 Hi, I'm wondering if this is even possible. I would like to show a certain <div> section depending on the id of the user. Currently I have the following code for the onclick, but this event needs to happen as soon at the user reaches the page. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <style type="text/css"> <!-- .lay { display: none; position: relative; } --> </style> <script> n = 3; // number of hidden layers function show(a){ for(i=1;i<=n;i++){ document.getElementById('t'+i).style.display = 'none'; } document.getElementById('t'+a).style.display = 'inline'; } </script> </head> <body> <div style="position:absolute"> <a href="#" onclick="show(1)">section 1</a><br> <div id="t1" class="lay">some comment here<br>section 1<br>test </div><br> <a href="#" onclick="show(2)">section 2</a><br> <div id="t2" class="lay">some comment here<br>section 2<br>test</div><br> <a href="#" onclick="show(3)">section 3</a><br> <div id="t3" class="lay">some comment here<br>section 3<br>test</div> </div> </body> </html> How do I show a certain section to the user when they arrive at the page? For example, User 1 will only be able to see Section 1; User 2 sees Section 2 and so forth. Can someone please help me out? **note, this site is in combination with PHP** Link to comment https://forums.phpfreaks.com/topic/132440-showhide/ Share on other sites More sharing options...
rarebit Posted November 12, 2008 Share Posted November 12, 2008 Yes, this is a php issue really, because if you do it with css alone, then everybodies data would be available in the source of the page. When you say: How do I show a certain section to the user when they arrive at the page?, they are served a generated page after they've requested it, never actually arrive. If you see the distinction! Link to comment https://forums.phpfreaks.com/topic/132440-showhide/#findComment-688595 Share on other sites More sharing options...
true2self Posted November 12, 2008 Author Share Posted November 12, 2008 I mean that I have a page with all the sections like I have in the code above. But whenever that user opens the page it will only show a certain section within the page even though all the sections are listed without having to click the link. I hope i'm clear. Link to comment https://forums.phpfreaks.com/topic/132440-showhide/#findComment-688602 Share on other sites More sharing options...
rarebit Posted November 12, 2008 Share Posted November 12, 2008 When I do similar for a tree menu and don't want it js based, I'll have the part written by php at the last point (as to override all before), e.g. ... <div id="t2" class="lay" style="display:inline;">some comment here<br>section 2<br>test</div> ... The js way would to be call a page init script from within the body tag and call the following with: document.getElementById('t2').style.display = 'inline'; Link to comment https://forums.phpfreaks.com/topic/132440-showhide/#findComment-688610 Share on other sites More sharing options...
dropfaith Posted November 12, 2008 Share Posted November 12, 2008 possible with sessions if session id = 1 show this else session id 2 show this and so on but your best bet is the first answer with php generating the sections based o id Link to comment https://forums.phpfreaks.com/topic/132440-showhide/#findComment-688628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.