Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2006
    Location
    Bronx, New York
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    run js code if user is logged in (determined with php)

    I want to use php to determine if user is logged in and then run js to change the div's display to none based on login status, something like:

    Code:
    if ($loggined) {
    
    document.getElementById.('header').style.display = 'none';
    
    }
    Can someone point me in the right direction? js is so much more difficult than php! Thanks!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Extree dot ...

    Code:
    document.getElementById.('header').style.display = 'none';
    Any particular reason you're using JS to do this?

  • #3
    New Coder
    Join Date
    Feb 2006
    Location
    Bronx, New York
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That doesn't work:
    Code:
    if ($loggedin) {
    	?>
    	<script type="text/javascript">
    	    document.getElementById.('header').style.display = 'none';
            </script>
    <?php 
    }
    ?>
    The way I have it now, it's creating the css if loggedin, but it's in the body, not the head. I don't have access to the head, and I don't think it's good form to have style tags in the body, no?

    Do you have a suggestion on how to do this?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Maybe I should have made it bigger ....

    document.getElementById.('header').style.display = 'none';

    Function call, with argument. Lose the dot.

    Style tags do go in the document head- but they work just fine in the body, and are doing so all over the web. The 'access' comment was what I was thinking of, just curious. The above script statement needs to be below the element html to work, btw. Keep in mind that this may mess up your layout, as 'display: none' removes the element completely from the page ('visibility:hidden' will still reserve the space).

  • #5
    New Coder
    Join Date
    Feb 2006
    Location
    Bronx, New York
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I thought you were saying to put in the dot, not to lose it. Was working til 3 a.m. last night so am not with-it today.

    Anyway, it worked! Thanks for your advice and guidance. Learned some good stuff today!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •