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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving ASP session value in an included .js file 1

Status
Not open for further replies.

timtom

Programmer
Jul 12, 2001
78
GB
In an website editing page I have an included .js file which writes a rich text editor to the screen. (This doesn't work as an asp include btw)

I need to get a variable containing the page content to the Javascript file so it can display it as part of its output but am unsure of how. I have already set an asp session with the content - can I transfer this to a javascript cookie or something?

I have used the <script src=&quot;blah.js&quot;> method of including the .js file.

Please help. Thanks.
User_timtom.jpg
WASN'T FIT ENOUGH FOR THE POLICE FORCE
 
see when you want some dynamic variable to be accessed by an ASP page, you need to have that page extension as .ASP.

Here you are using <script src=&quot;blah.js&quot;> .

Just consider using an HTM include within an ASP page and try to put some variable in that. You cant do it because htm extension will not allow you to put any server side code.

Same case here.Wht you do is before putting an include
<script src=&quot;blah.js&quot;> , just take session value in a variable.Just make sure that in all situations you get the value.And then concatenate the variable through a javascript way in your include.

&quot;+ VarName +&quot;..

I am confident, you must be able to do it..

Rushi Shroff Rushi@emqube.com
&quot;Life is beautiful.&quot;
 
Thanks Rushi,
I was aware that I couldn't use actual ASP code in the include - I'm just looking for a way to set a Javascript variable in it's Parent ASP page.

I tried your suggestion of making a plain variable in asp before including the js file and accessing it via &quot; + MyVariable + &quot;, but I just get a script error saying 'MyVariable is undefined.

I was thinking if I could set a javascript cookie (or something) in the parent ASP page (where I have the information to hand) then I will be able to access it in the .JS file. But I don't know how to do that :)
User_timtom.jpg
WASN'T FIT ENOUGH FOR THE POLICE FORCE
 
Why can't you use a response.write to write a <SCRIPT> tag with the vairable name set. Below that you include your normal <SCRIPT> tag and the variable from the ASP generated tag should be available to you by means of the global namespace.

Just a thought.

William
Software Engineer
ICQ No. 56047340
 
Of Course! Thanks Williamu. There's just a slight problem if someone could help me and then I'll go away, promise.


The data I want to put into the variable just happens to be HTML and thus full of &quot;s (quotes)

(e.g. <td bgcolor=&quot;pink&quot;> etc.)

As soon as the javascript hits the first &quot;, it stops working. Doing a Replace on &quot;s gets me an ASP error. Does anyone know how to strip the variable of &quot;s in ASP before giving it to the Javascript?

Thanks
Sarah :)
User_timtom.jpg
WASN'T FIT ENOUGH FOR THE POLICE FORCE
 
Well in this instance you can dispense with the &quot; around the Pink (and other attributes as well) since it's not really required. But I think you can use the \ char to escape it I'm not 100% sure.

HTH
William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top