J_V
J_V

Reputation: 1

How to get the value of that input text?

I have two roles admin and student, if the role is student then I want to hide the admin menu.

Html

<input id="role" value='<?php echo $_SESSION[$config["session"]]["role"];?>'>

Javascript

function loadPage(){
   if($("#role").val() == "student"){
       $("#admin-menu").hide()
   }
}

Upvotes: 0

Views: 70

Answers (2)

Asad Arif
Asad Arif

Reputation: 31

Call your function after document load.

$(document).ready(function() {
loadPage();
});

Upvotes: 1

Alt Zh
Alt Zh

Reputation: 59

You could add this to your menu container class

<?= ($_SESSION[$config["session"]]["role"] != admin ? 'hidden' : '') ?>

It would add class 'hidden' if the user's role is not admin

But the better practice is to use separate views for different user roles or|and do not render admin menu at all

Upvotes: 1

Related Questions