...

View Full Version : run js code if user is logged in (determined with php)



donmarvin
06-02-2009, 06:44 PM
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:


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!

adios
06-02-2009, 06:51 PM
Extree dot ...


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

Any particular reason you're using JS to do this?

donmarvin
06-02-2009, 07:02 PM
That doesn't work:

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?

adios
06-02-2009, 07:12 PM
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).

donmarvin
06-02-2009, 07:21 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum