If you want the value of the $user perl var to be interpolated in that string, then Perl needs to be the one that does that interpolation before sending that data to the browser. In order to do that, the string that includes the $user var needs to be within double quotes or one of the other operators that allow interpolation.

Please show the surrounding perl code where that document.writeln statement is being used so we can show you how to correct it.

If you're passing $user to index.pl via the query string, as you've shown, and index.pl is outputting the javascript statement you posted, then there's no logical reason to use an ajax call to another script to retrieve the same info you've already passed in the query string.

2) Wrap the relevant javascript in a function, then call the function from your HTML supplying interpolated $user as an argument.

That's what I would like to do, but instead of supplying interpolated $user as an argument in html I would rather save the $user value from first page when a user logs in, to a cookie and have javascript to read/retrieve the $user value from the cookie as I don't want to pass around $user variable from script to script as there are so many scripts in my application. If you find links which may help me do that, this will be really helpful. Thanks much !! Terry

I don't want to pass around $user variable from script to script as there are so many scripts in my application

I think I remember seeing a snippet of your code where you used CGI::Session to create a user session. This is where you could store data such as user. Pass this data to your HTML / javascript whenever you need it, in the same manner as when you pass the current page number to your pagination plugin.

As advised previously, you should break your application into functions, or atleast code that you need to regularly repeat, and put into an external file accessible by all your scripts. One of these functions could fetch user data and be called in each of your scripts i.e. my $user_data = fetch_user_data( @args ). We won't delve into object orientated Perl just yet!

Looks like we're dealing with a person suffering from dual personality.

Based on the threads I've seen from Terry/Tonya it appears that he/she is deliberately wanting to find the most difficult approach to a problem and wants us to fix the convoluted solution that he/she has decided on using.

Is it really worth wasting our time providing sound recommendations to a person that doesn't want or care about following those recommendations?

Hi, Thanks for your advices, btw. Tonya Lepski is my girlfriend I am getting her to do postings at stackoverflow as I don't have an account there !! we're both just students.

Ron, My application is just about to finish and I do not want to do everything all over again but ofcourse for the next project I will be using the most recognized approaches and tools, so for now I am stuck with that jquery which is used globally through out in my application and trying to find a way to store $user name to a cookie and read it through that js script to be displayed on all the pages.

Fishmonger has given you great advice, you should use it. Indeed his and your advices are very valuable but I have gone a long way in this application I don't wanna change the framework like using Template Toolkit at this point, I do not wanna do everything all over again, but I am making notes of everything and saving links etc for my next project, as you must have realized this is my very first project !!

Quote

I don't want to pass around $user variable from script to script as there are so many scripts in my application

I think I remember seeing a snippet of your code where you used CGI::Session to create a user session. This is where you could store data such as user. Pass this data to your HTML / javascript whenever you need it, in the same manner as when you pass the current page number to your pagination plugin. Yes, you're right I am using it in my application but that java script is providing a template for my project and is used globally throughout the application, there are couple of issues with using CGI::Session for the purpose like I don't know how to pass variables stored in CGI Session to JS script or how to make JS script to read the value from CGI Session, and if I just use CGI Session to retrieve $user value and display it on the page using perl then given the framework provided by the JS script I cannot place it exactly where I want to do it, that is why I am sticking with that JS script, its way easier for me to use Perl and get helped as there are so many Gurus and Monks like you to always help me out.

As advised previously, you should break your application into functions, or atleast code that you need to regularly repeat, and put into an external file accessible by all your scripts. One of these functions could fetch user data and be called in each of your scripts i.e. my $user_data = fetch_user_data( @args ). We won't delve into object orientated Perl just yet! With this approach, again the problem is of placement/positioning of that information on the webpage, if I go for something outside of that JS script framework I cannot place where it should be, I have described that in one of my above comments, see the picture attached.

Are you really trying to set the cookie using backticks (system call) directly from Perl?

To do it the way you want to, I guess my approach would be to write the header myself when I set the session as per the CGI::Session documentation, but set the session cookie as well as a user cookie. The user cookie should not be http only otherwise it won't be accessible by your javascript.

# minimum options set in this example, you'll have to set all those that are relevant to you. my $session_cookie = CGI::Cookie->new(-name=>$session->name, -value=>$session->id, -httponly=>1); my $user_cookie = CGI::Cookie->new(-name=>'user', -value=>$user, -httponly=>0);

You could of course set the cookie using the javascript plugin as you have already attempted to do, but it would probably be a little trickier to implement. You would need to do it on the page you redirect to after logging in, which would require fetching the user from the session, it would be poor practice to fetch from the user param.

You're absolutely right, it does appear that a lot of advice doesn't get applied. I think this is partly down to lack of both understanding and experience, Terry has his mind set on what he thinks is the quickest / easiest solution, but we know otherwise. For a first project, he has most definitely jumped into the deep end of the pool. If Terry provided standalone programs (not always possible) that represent his problems to aid his descriptions of the problems, I would be much more forgiving due to this effort. When we understand the problem itself, but not necessarily the approach he has taken to solve the problem, we can only provide advice, good advice.

Write a standalone .html that represents this problem and post the code here (attach any relevant .js). Use a javascript debugger such as firefox firebug to check for javascript errors. If there are errors, then its possible the menu won't get written.

That will work, but I want to do is to read and assign user name from cookie from within the JS SCRIPT so the links are properly positioned on the webpage, and that's what I have been asking around and that's what I am trying to do. if I print those links the way you have done these links will not be properly aligned at the top right hand corner just above the menu bar end, please see the picture attached in my above comment.

Attached is the html file with all the referenced scripts and css files.