Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu options show/hide and enable/disable

Status
Not open for further replies.

dswitzer

Technical User
Aug 2, 2002
298
US
I don't use javascript for much so I'm pretty unfamiliar with it and hope someone can point me in the right direction.

I want to show/hide and enable/disable these menu option based on the users network login.

I have the users login in a variable (let's say it is "userlogon"). So for example:

1. If userlogon='Admin' -- then show the administration section of the menu. If userlogon<>'Admin' do not show the administration menu option (collapse menu down so there is no gap).

2. What if I wanted to show all options instead of hiding them? So -- all Administration menu is displayed regardless of userlogon -- but if userlogon<>'Admin' then the suboption1 & 2 are disabled?

Menu (in a div tag):
Code:
<script language="JavaScript" type="text/javascript"><!--
			var animMenu =
			[
				[null, 'Home', 'mainHome.asp', '_self', 'Main Page',
				],
				_cmSplit,
				[null, 'Search', 'serviceSearch.asp', '_self', 'Search',
				],
				_cmSplit,
				[null, 'Sales', null, '_self', 'Administration',
					[null, suboption1, 'suboption1.asp', null, null],
					[null, 'suboption2', 'suboption2.asp', null, null],
				],
				_cmSplit,
				[null, 'Service', 'serviceSelect.asp', '_self', 'Service',
				],
				_cmSplit,
				[null, 'Analysis', 'analysesMain.asp', '_self', 'Analysis',   
				]

			];
			cmDraw ('menuDiv', animMenu, 'hbr', cmThemeOffice, 'ThemeOffice');
			--></script>

Ideas?

Thanks.

 
dswitzer, having this functionality in your application is a good idea. However, your method of delivery is a bit unsafe. Using client side javascript to show/hide different menus can easily be hacked by anybody that knows what they're doing, allowing a user to view any of the admin menus. What you're proposing should probably be done server side with a "language" such as ASP or PHP.

-kaht

Do the chickens have large talons?
 
Appreciate the feedback and "best practices" tips.

I wanted to keep the explanation simple -- but I am not looking at the menu-display as my security system -- I am using it as an "option limiting" device -- so the users are not overwhelmed with options they have no use for. The addition of the 'Administration' option probably led you to that conclusion -- sorry for the confusion.

That said, it seems easy enough in concept to pass a variable into the javascript, do some if-thens and decide what to display or disable...

Can anyone assist by giving me direction on how to go about doing this? I will keep struggling with this in the meantime.

 
dswitzer, without seeing any more of your code it's hard to tell you what do modify. You've only provided an array and a call to a function, but have not provided any code in the function or even defined how your menus are displayed. This is the best I can give you w/ the information provided. I created a menu of radio buttons, and display them depending on whether you click the admin or user button. This should be enough for you to modify your code to compensate.
Code:
<script language=javascript>
function adminMenu(bool) {
   rad = document.forms["blahForm"].elements["blahRadio"];
   //give users access to reports page only
   //parentElement refers to the DIV that contains the radio and radio label
   rad[0].parentElement.style.display = (bool) ? 'block' : 'none';
   rad[1].parentElement.style.display = 'block';
   rad[2].parentElement.style.display = (bool) ? 'block' : 'none';
}
</script>
<body>
<form name=blahForm>
<div><input type=radio name=blahRadio>Go to search page.</div><br>
<div><input type=radio name=blahRadio>Go to reports page.</div><br>
<div><input type=radio name=blahRadio>Go to edit page.</div><br><br>
<input type=button value='click for admin options' onclick='adminMenu(true)'>
<input type=button value='click for user options' onclick='adminMenu(false)'>
</form>
</body>

-kaht

Do the chickens have large talons?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top