The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Need help with javascript to hide button

View previous topic View next topic Go down

Solved Need help with javascript to hide button

Post by Van-Helsing on 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
Hyperactive

Male Posts : 2198
Reputation : 82
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Sir. Mayo on 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
Forumember

Male Posts : 963
Reputation : 85
Language : English, Some french.
Location : Working 11Pm-7Am EST I will try to respond ASAP

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

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Van-Helsing on 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
Hyperactive

Male Posts : 2198
Reputation : 82
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Sir. Mayo on 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
Forumember

Male Posts : 963
Reputation : 85
Language : English, Some french.
Location : Working 11Pm-7Am EST I will try to respond ASAP

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

Back to top Go down

Solved Re: Need help with javascript to hide button

Post by Ange Tuteur on 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Need help with javascript to hide button

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

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

Best Regards,
Black-Shadow

Van-Helsing
Hyperactive

Male Posts : 2198
Reputation : 82
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Solved Re: Need help with javascript to hide button

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

You're welcome ^^

Topic archived

Have a nice day. Smile

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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