PDA

View Full Version : Server Side Code within Javascript Menu?


DogonSirius
04-28-2003, 05:43 PM
I am trying to develop a cascading menu, but need to enclose the code with server side script (using business logic rules). I need to disable certain menu items when a user's status in the database is a certain value.

It is my understanding that you cannot wrap server side code within Javascript, but that you can with DHTML. If I want to do the cascading menu in Javascript, would I need to use out.println statements in JSP?

Can I do this easily with Javascript or would it be better to use DHTML?

Awaiting your replies...

Wayne

Roy Sinclair
04-28-2003, 07:19 PM
You can't interact with the end-user in server side code in the same fashion that DHTML code can, however you can have the server side code write the appropriate menu items according to your database values. I do this exact thing in a few applications, the user sees different menu items depending on who the user is and what capabilities they should see.

The menu code running in the browser doesn't know the difference it only shows the menu options it is given and the pages the user doesn't see also check and send the user back to the menu page if they have the url and enter it by hand.

DogonSirius
04-28-2003, 07:35 PM
Thanks for your response, Roy!! That's what I thought. I would need to have the server side code generate the Javascript for the menu, right? I'm using JSP instead of ASP.

I like the cascading menu that are written in Javascript better than the ones in DHTL. So if I wanted to use Javascript for my menu, I could use out.println lines to write the Javascript code. Is that correct?

Wayne

DogonSirius
04-28-2003, 07:41 PM
Thanks for your response, Roy!! That's what I thought. I would need to have the server side code generate the Javascript for the menu, right? I'm using JSP instead of ASP.

I like the cascading menu that are written in Javascript better than the ones in DHTL. So if I wanted to use Javascript for my menu, I could use out.println lines to write the Javascript code. Is that correct?

Wayne

Roy Sinclair
04-28-2003, 07:47 PM
Sure, your server side code (the language used at the server doesn't really matter) just has to output the appropriate code for the browser. As long as what the browser sees is valid code (hmtl and/or javascript) it should work just fine. Remember to use view-source to see just what your server side code sent to the browser.

As far as using out.println is concerned, I really can't tell because I'm not a PHP person but it "sounds" right.