How to hide a div?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
actarus99
User
Posts: 38

How to hide a div?

Post by actarus99 »

Hi,
I set this code in Page_load of the listpage in order to hide a div with id="fmad"

function Page_Load()
{
$('#fmad').hide();
}

but I get js error

Anyone can help please?


arbei
User
Posts: 9787

Post by arbei »

  1. Page_Load() is server event, not JavaScript,
  2. When the server event is fired, there is no HTML yet.
  3. You should use client side Startup Script.

mobhar
User
Posts: 11905

Post by mobhar »

You should put the jQuery code under Client Scripts -> Startup Script that belongs to the current page, and not in the server event.


actarus99
User
Posts: 38

Post by actarus99 »

It works well, tnx
but when I set this:

$user_level = CurrentUserLevel();
if($user_level == 0 {
$('#fmad').hide();
}
else
{
$('#fmad').show();
}

the div is showing independently of the user level


arbei
User
Posts: 9787

Post by arbei »

CurrentUserLevel() is PHP, you cannot mix server side PHP code into client side JavaScript, you should output it by, e.g. <?= CurrentUserLevel() ?>. (Note that you have syntax error also.)


mobhar
User
Posts: 11905

Post by mobhar »

You may try:

$user_level = <?= CurrentUserLevel() ?>;
if ($user_level == 0) {
    $('#fmad').hide();
} else {
    $('#fmad').show();
}

actarus99
User
Posts: 38

Post by actarus99 »

Thank You, it works


Post Reply