The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Need help with javascript to hide button

3 posters

Go down

Solved Need help with javascript to hide button

Post by Van-Helsing April 28th 2015, 12:28 pm

Hello,
I am using the following javascript to hide a button from members:

Code:

     jQuery(document).ready(function(){if ((_userdata['user_level'] != '1') || (_userdata["user_level"] != '2')) {
   $('#elem1').hide())}};

but it is not working. Can someone help me please?
Van-Helsing
Van-Helsing
Hyperactive

Male Posts : 2431
Reputation : 116
Language : English, Greek

http://itexperts.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Sir. Mayo April 28th 2015, 3:25 pm

Hello,

Just a few questions for you:
1)What is your forum Version
2) What is you forum URL
3) Did you check the box for all pages in the JavaScript settings?
4) Did you enable JavaScript code management?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 980
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Van-Helsing April 28th 2015, 3:35 pm

Sir. Mayo wrote:Hello,

Just a few questions for you:
1)What is your forum Version
2) What is you forum URL
3) Did you check the box for all pages in the JavaScript settings?
4) Did you enable JavaScript code management?
Hello @Sir. Mayo
My forum version is PunBB I have set the code in all the pages, I have enabled my javascripts management and my forum url is here.

Best Regards,
Black-Shadow
Van-Helsing
Van-Helsing
Hyperactive

Male Posts : 2431
Reputation : 116
Language : English, Greek

http://itexperts.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Sir. Mayo April 28th 2015, 3:37 pm

Thanks.
Nice Forum By the way.
What button where you trying to hide and what users/group where you trying to hide if from?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 980
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Ange Tuteur April 28th 2015, 9:01 pm

Hi @Black-Shadow,

The code looked a bit messy on the ending parentheses and brackets. I cleaned it up for you :
Code:
$(function(){
  if (!_userdata.user_level) $('#elem1').hide();
});

If it's still not hidden, check the attributes of the element you're trying to hide to see if you have to correct ID.

You were hiding this for non-staff, correct ? I'll show you a few simplified methods for checking the user state. See the comments for the purpose :
Code:
if (!_userdata.user_level) console.log('MEMBER'); // if the member is NOT staff e.g. user level == 0

if (_userdata.user_level) console.log('STAFF'); if the member IS staff e.g. user level 1 or 2

// after this you can check the values using comparison symbols.
if (_userdata.user_level == 1) console.log('ADMIN'); // user level 1 == admin

if (_userdata.user_level == 2) console.log('MODERATOR'); // user level 2 == mod

You'll see the first two conditions I used no comparison symbols. It's simple boolean math 0 == false and anything above 0 is true. More simply, the exclamation point (!) inverts our condition performing a check for false values.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Van-Helsing April 28th 2015, 9:59 pm

Hello @Ange Tuteur,
Thank you very much it has been solved.

Best Regards,
Black-Shadow
Van-Helsing
Van-Helsing
Hyperactive

Male Posts : 2431
Reputation : 116
Language : English, Greek

http://itexperts.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Ange Tuteur April 28th 2015, 10:01 pm

You're welcome ^^

Topic archived

Have a nice day. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum