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

Calling a javascript var from asp 1

Status
Not open for further replies.

lxon

Technical User
Aug 25, 2002
7
SG
How do i call a javascript variable from an asp page?
 
Hi,

What are you trying to do? can you be a little bit more specific?

Bye.
 
alright the code is something like that
var jStatus = document.cookie.indexOf('strStatus');
strStatus is the name of the cookie
n jStatus is what i'm trying to call from the asp file.
i just wanna to display the value of jStatus on the asp file.
 
Well, the first issue you have is that your javascript is client sider and your asp is server side, this means you can only pass the javascript value to the next page as the server side code has already executed and gone away.
One solution would be to embed the value in the querystring of the address and use Request.QueryString on the ASP page to get the value.

Let me state again, for the record, you cannot pass the javascript variable to the ASP on the same page. That ASP script has already executed and created the client side script that is being processed. Once the page shows up in the browser and any client side functions start, the ASP script is gone. You cannot call the javascript value from the ASP because when the ASP script is running, the javascript has not executed yet and that variable does not exist yet.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
if that is the case is can i make use of my ASP variable to run a javascript?
example

i have a variable status:
status can be admin or guest depending on the login type

so
the code will look some how like

<%ASP CODE
if status = &quot;admin&quot;%>
run some javascript

<%ASP CODE
else if status = &quot;guest&quot;%>
run other javascript

is this possible?

AIM of this is to make use of the ASP variable to be used on a side menu to disable some buttons which are javascript depends on admin or guest. So like admin will see 5 javascript buttons and guest will also see the same but will be unable to click the buttons
 
I'm assuming you are having the person login in some manner, why not just get the status during verification and add it to your forms on every page?
Another option would be accessing the cookie from ASP, or creating another strictly for your ASP script (cross language cookie references can be a pain at times).
In order to get your javascript variable to the ASp it will have to be passed as either part of the Url (querystring) or part of a form to get it to the next ASP script, so you may as well latch on to it from the beginning.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top