Page 1 of 1

How to hide a div?

Posted: Thu Aug 29, 2024 6:53 pm
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?


Re: How to hide a div?

Posted: Thu Aug 29, 2024 7:06 pm
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.

Re: How to hide a div?

Posted: Thu Aug 29, 2024 7:07 pm
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.


Re: How to hide a div?

Posted: Thu Aug 29, 2024 7:52 pm
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


Re: How to hide a div?

Posted: Thu Aug 29, 2024 9:35 pm
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.)


Re: How to hide a div?

Posted: Fri Aug 30, 2024 9:07 am
by mobhar

You may try:

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

Re: How to hide a div?

Posted: Fri Aug 30, 2024 7:40 pm
by actarus99

Thank You, it works