Jump to content

show/hide <div>


true2self

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.