having an ASP variable in javascript

M

middletree

I have a menu that I use on my Intranet app, and while I did try to replace
it recently, I ended up going back to it. It's built entirely with
javascript, and works great.

However, there are certain pages where I would like to be able to put an
item into a querystring for a link. That is, I might have a link which is
worded "Add to this ticket" and the hyperlink associated with that text is
along the lines of "addtoticket.asp?ticketid=1000"

I am not able to figure out how to have an ASP variable into a link built by
javascript. This is the main question. How can I have the ASP variable in a
javascript?

Because it's Inranet, I don't have the page to show you. However, I have
zipped up the two javascript files and placed them at
www.middletree.net/js.zip

Also, in this case, IE-specific code will not be a problem. 100% of users
are on IE5+
 
T

TomB

<%
'This is asp so it runs on the server

Dim aVar
aVar="1000"
%>
<script language="Javascript">
//this runs on the client, except for the <%=aVar%> part which gets
tossed in on the server
function AddToTicket()
{
window.open('theUrl.asp?id=<%=aVar%>');
}
</script>
 
C

Curt_C [MVP]

replace
addtoticket.asp?ticketid=1000
with
addtoticket.asp?ticketid=<%=YourAspVariable%>
 
M

Mark Schupp

The files where you want to substitute variables are JS files and are not
processed by ASP. There are a couple of possibilities.

1. make the js files .asp files and include asp code to set the
variables.

2. add a javacript variable declaration to the asp page before including
the script file. then use that variable in the script file.

....
<script language="javascript">
var strTicketID = "<%=YourAspVariable%>";
</script>

<script language="javascript" src="menu.js"></script>
....

in menu.js

self.location="addtoticket.asp?ticketid=" + strTicketID;

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
 
M

middletree

Comments below:

Mark Schupp said:
The files where you want to substitute variables are JS files and are not
processed by ASP.

That was my point in the OP. Guess I didn't communicate it well.
There are a couple of possibilities. variables.
I have no idea how to do this, or what you mean, exactly.
2. add a javacript variable declaration to the asp page before including
the script file. then use that variable in the script file.

...
<script language="javascript">
var strTicketID = "<%=YourAspVariable%>";
</script>

<script language="javascript" src="menu.js"></script>
...

in menu.js

self.location="addtoticket.asp?ticketid=" + strTicketID;

Hmm, this looks like something I could do. Let me check and I'll post my
results.

thanks very much!
 
M

middletree

Well, there's no ASP, really. I mean, this menu is built entirely in js. I
have the js you can look at in the zip file I mentioned earlier, but on the
ASP page, I just have the <script> code which points to the external js
file.
 
V

Vilmar Brazão de Oliveira

HI people,
Put the asp result in a html hidden element, so afterwards attribute it to
javascript variable, thus:
<input type="hidden" name="hidTest" value="<%=VarASP%>">

<script>
var JsTest = hidTest.value;
</script>

bye and good luck1

--

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
 
M

Mark Schupp

It works for me all the time (not the exact same example).

Show exactly what you did in the .asp file and in the associated .js file.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
 
M

middletree

I think my problem was I had the +strTicketID inside the quotes. Pretty
dumb.

Anyway, it works now.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top