ASP, Javascript and parsing

Discussion in 'ASP General' started by Martin Walke, Mar 24, 2006.

  1. Martin Walke

    Martin Walke Guest

    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
    Martin Walke, Mar 24, 2006
    #1
    1. Advertising

  2. Martin Walke

    Evertjan. Guest

    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]

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 24, 2006
    #2
    1. Advertising

  3. "Martin Walke" <martin.walke_no_spam@vega_dot_co_dot_uk> wrote in message
    news:...
    > 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.
    Anthony Jones, Mar 24, 2006
    #3
  4. Martin Walke wrote:
    > [ <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.
    Dave Anderson, Mar 24, 2006
    #4
  5. Martin Walke

    Martin Walke Guest

    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


    "Anthony Jones" <> wrote in message
    news:%...
    >
    > "Martin Walke" <martin.walke_no_spam@vega_dot_co_dot_uk> wrote in message
    > news:...
    >> 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.
    >
    >
    Martin Walke, Mar 27, 2006
    #5
  6. Martin Walke wrote:
    > 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.
    Dave Anderson, Mar 27, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    869
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    571
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    600
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    424
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    718
    John Levine
    Feb 2, 2012
Loading...

Share This Page