ASP, Javascript and parsing

M

Martin Walke

Hi all,

Can someone help me out here? I'm been using ASP and VBScript for some years
but have just ventured into the realms of using server side Javascript and
apart from hitting various niggerly problems, this one baffles me.

This is a very simplistic example of the problem.

<%@ Language="JavaScript"%>

<html>
<body>

Here it is
<script language="javascript" runat="server">
Response.Write("in the")
</script>
middle

</body>
</html>

When I run this I get

"Here it is middle in the" rather than "Here it is in the middle".

Can someone tell me why? If I use <%= then it's fine but my main program is
using a javascript server side include which I'm including by using the
<script src ....> as I can't get the <!--#include method to work.

Am I confusing myself totally by messing up what I thought to be VBScript
and Javascript commands? Or is it something to do with the way in which the
page in parsed for server side commands?

TIA
Confused Martin
 
E

Evertjan.

Martin Walke wrote on 24 mrt 2006 in
microsoft.public.inetserver.asp.general:
Can someone help me out here? I'm been using ASP and VBScript for some
years but have just ventured into the realms of using server side
Javascript and apart from hitting various niggerly problems, this one
baffles me.

This is a very simplistic example of the problem.

<%@ Language="JavaScript"%>

<html>
<body>

Here it is
<script language="javascript" runat="server">
Response.Write("in the")
</script>
middle

</body>
</html>

try:

<%@ Language="JScript"%>
<html>
<body>
Here it is
<%
Response.Write("in the")
%>
middle
</body>
</html>

============================

runat="server" scripts of the other language run first
then the <% %> scripts inline with the html
then the runat="server" scripts of the same language.

If you think long about ik you will come to like it.

A better explanation, with examples:
<http://www.aspfaq.com/show.asp?id=2045>

[It is always a good idea to read the FAQ before asking questions]
 
A

Anthony Jones

Martin Walke said:
Hi all,

Can someone help me out here? I'm been using ASP and VBScript for some years
but have just ventured into the realms of using server side Javascript and
apart from hitting various niggerly problems, this one baffles me.

This is a very simplistic example of the problem.

<%@ Language="JavaScript"%>

<html>
<body>

Here it is
<script language="javascript" runat="server">
Response.Write("in the")
</script>
middle

</body>
</html>

When I run this I get

"Here it is middle in the" rather than "Here it is in the middle".

Can someone tell me why? If I use <%= then it's fine but my main program is
using a javascript server side include which I'm including by using the
<script src ....> as I can't get the <!--#include method to work.

Am I confusing myself totally by messing up what I thought to be VBScript
and Javascript commands? Or is it something to do with the way in which the
page in parsed for server side commands?

TIA
Confused Martin


First off you can't preform inline response.writes in a <script
runat="server"> tag. It needs to be <% %>

Secondly isn't the real issue here that <!-- #includes aren't working. Why
not?

Thirdly if you change the script tag language to VBScript it appears to run
first before the rest of the document. Then if you change <% language to
VBScript it runs after the rest of the document. If you then change the
script language back to Javascript it runs before the rest of the document.

I won't try to describe here why that so but it does actually make sense.

Anthony.
 
D

Dave Anderson

Martin said:
[ <script runat=server> -vs- <%%> ]
Can someone tell me why? If I use <%= then it's fine but my main
program is using a javascript server side include which I'm including
by using the <script src ....> as I can't get the <!--#include method
to work.
http://aspfaq.com/show.asp?id=2045


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
M

Martin Walke

Thanks Anthony and Dave,

Your link, Dave, gives the detail behind what Anthony is hinting at. I'd
seen this info before but couldn't nail it down.

Seeing this info gives the inherent reason why the #include was not working.
I have a large number of objects defined in the include file that weren't
being recognised by the rest of the code due to the reasons mentioned in
Dave's link.

You *could* almost use this order parsing to your advantage but could be
messy from a maintenance point of view. Anyway......

Thanks again guys. I'll just need to re-structure my code.

Martin
 
D

Dave Anderson

Martin said:
Thanks Anthony and Dave,

Your link, Dave, gives the detail behind what Anthony is hinting at.
I'd seen this info before but couldn't nail it down.

Seeing this info gives the inherent reason why the #include was not
working. I have a large number of objects defined in the include file
that weren't being recognised by the rest of the code due to the
reasons mentioned in Dave's link.

You *could* almost use this order parsing to your advantage but could
be messy from a maintenance point of view. Anyway......

Thanks again guys. I'll just need to re-structure my code.

The situation may not be as dire as you think. My strong recommendation for
using <script runat=server> is to encapsulate everything in functions. If
you do so, you can call those functions from anywhere in the execution order
(even if the called function is in the last order group). I have no idea how
that plays with #include directives, but you could always try it and let us
know.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top