For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2004 > JavaScript not working with ASP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JavaScript not working with ASP
Web Spinner

2004-03-28, 9:57 pm

I am running Windows 2000 and I can't seem to get my JavaScript
working with ASP. I placed my HTML code in a file called x.asp
under c:\Inetpub\wwwroot, and I placed my JavaScript code in a
file called updated.js under c:\Inetpub\wwwroot\scripts.

When I rename x.asp to x.htm and execute it as a html file,
the JavaScript code works, however when it's x.asp and I
execute it by typing in the browser http://localhost/x.asp,
it doesn't work!

I know the example doesn't actually have any asp code in it,
but even when it does, my JavaScript does not work.

I've looked around, but can't seem to find information on how
to fix this. Can anyone help me out?


----------c:\Inetpub\wwwroot\scripts\updated.js--------------------------
update = new Date(document.lastModified)
theMonth = update.getMonth() + 1
theDate = update.getDate()
theYear = update.getYear()
document.writeln("<I>Last updated: " + theDate + "/" + theMonth + "/" +
theYear + "</I>")
----------c:\Inetpub\wwwroot\scripts\updated.js--------------------------


---------c:\Inetpub\wwwroot\x.asp---------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<TITLE>Test</TITLE>
<LINK rev="made" href="">
<META name="generator" content="NoteTab Light 4.95">
<META name="author" content="Web Spinner">
<META name="description" content="Test">
<META name="keywords" content="Test">
</HEAD>

<BODY bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink=
"#800080" alink="#FF0000">

<SCRIPT language="JavaScript" src="scripts/updated.js" type=
"text/javascript">
</SCRIPT>

</BODY>
</HTML>
---------c:\Inetpub\wwwroot\x.asp---------------------------------
Bob Barrows

2004-03-28, 9:57 pm

Web Spinner wrote:
> I am running Windows 2000 and I can't seem to get my JavaScript
> working with ASP. I placed my HTML code in a file called x.asp
> under c:\Inetpub\wwwroot, and I placed my JavaScript code in a
> file called updated.js under c:\Inetpub\wwwroot\scripts.
>
> When I rename x.asp to x.htm and execute it as a html file,
> the JavaScript code works, however when it's x.asp and I
> execute it by typing in the browser http://localhost/x.asp,
> it doesn't work!


What does "doesn't work" mean? We're not looking over your shoulder. Do you
get error messages? Incorrect results?

>
> I know the example doesn't actually have any asp code in it,


.... making this question off-topic for this newsgroup. :-)

However, I tried your code and cannot reproduce your problem. The page seems
to "work" fine on my server no matter which extension I use.

Create a page with only real asp code in it:

<%response.write "hello world"%>

When you run that in the browser, do you get a page with the words "hello
world"? If not, you may need to go into your IIS settings and turn asp on. I
seem to recall that asp is not on by default in IIS6.

Here is an article for you to look at:
http://www.aspfaq.com/show.asp?id=2147


Bob Barrows



--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Web Spinner

2004-03-29, 12:30 am

> What does "doesn't work" mean? We're not looking over your shoulder. Do you
> get error messages? Incorrect results?


The javascript code was supposed to display text indicating the date
of last modification of the x.asp document. It's not doing that. I
tried a simple statement like document.write("message") in the javascript
file and it would not even display that.

It seems to me like ASP could not locate that the JavaScript files are
under the "scripts" directory. I am just wondering if I had to
configure anything in IIS to let ASP know that it can find these files
under the "scripts" directory? Forgive my ignorance, but I am a bit new
to ASP.

>
>
> ... making this question off-topic for this newsgroup. :-)


Well it's supposed to work alongside ASP code, I only gave a simplified
example to help illustrate my problem. :-)

>
> However, I tried your code and cannot reproduce your problem. The page seems
> to "work" fine on my server no matter which extension I use.
>
> Create a page with only real asp code in it:
>
> <%response.write "hello world"%>
>
> When you run that in the browser, do you get a page with the words "hello
> world"? If not, you may need to go into your IIS settings and turn asp on. I
> seem to recall that asp is not on by default in IIS6.


Yes that works. All the ASP codes work. It's the JavaScript part
that doesn't work when it's ran as an ASP document.

Your help is very appreciated.
Mark Schupp

2004-03-29, 12:30 pm

Right-click on the page generated by ASP and "view source".
Make sure that the HTML being generated is as expected.

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


"Web Spinner" <webspinner@inbox.lv> wrote in message
news:b7c93f8d.0403282035.50a772b@posting.google.com...
you[color=darkred]
>
> The javascript code was supposed to display text indicating the date
> of last modification of the x.asp document. It's not doing that. I
> tried a simple statement like document.write("message") in the javascript
> file and it would not even display that.
>
> It seems to me like ASP could not locate that the JavaScript files are
> under the "scripts" directory. I am just wondering if I had to
> configure anything in IIS to let ASP know that it can find these files
> under the "scripts" directory? Forgive my ignorance, but I am a bit new
> to ASP.
>
>
> Well it's supposed to work alongside ASP code, I only gave a simplified
> example to help illustrate my problem. :-)
>
seems[color=darkred]
"hello[color=darkred]
on. I[color=darkred]
>
> Yes that works. All the ASP codes work. It's the JavaScript part
> that doesn't work when it's ran as an ASP document.
>
> Your help is very appreciated.



Web Spinner

2004-03-30, 11:30 am

"Mark Schupp" <mschupp@ielearning.com> wrote in message news:<#ycINnaFEHA.1840@TK2MSFTNGP12.phx.gbl>...
> Right-click on the page generated by ASP and "view source".
> Make sure that the HTML being generated is as expected.
>
> --
> Mark Schupp
> Head of Development
> Integrity eLearning
> www.ielearning.com


I did that and the generated HTML page has exactly the same
contents as the file "x.asp" as I orignally posted - this of
course is what's expected. I already did this with my other
ASP documents which actually has ASP VBscript code in it,
and it was generated according to the way I want it.

All the ASP stuff works. It's just the JavaScript that does
not work. I had the same problem even when running it on
another machine with PWS on it.

The JavaScript part works When I moved the javascript files
from c:\inetpub\wwwroot\scripts to c:\inetpub\wwwroot and
modified the x.asp file accordingly, ie:

<SCRIPT language="JavaScript" src="updated.js" type=
"text/javascript">
</SCRIPT>

However, I would like to keep things neat and tidy by
placing all my external javascript files under the script
directory.

My belief is that somehow, opening it as an ASP document
doesn't allow it to recognize that javascript files
are under the "scripts" directory. All I did so far
was create a "scripts" directory under c:\inetpub\wwwroot
and placed js files in it.

Is there anything else I need to configure to let IIS or PWS
know that javascript files are in a "scripts" subdirectory?
Mark Schupp

2004-03-30, 12:30 pm

It is the browser that is responsible for retrieving the script file based
on the HTML code that it is interpreting.

Can you post exactly what you see in "view source"?

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


"Web Spinner" <webspinner@inbox.lv> wrote in message
news:b7c93f8d.0403300753.3e5ec58@posting.google.com...
> "Mark Schupp" <mschupp@ielearning.com> wrote in message

news:<#ycINnaFEHA.1840@TK2MSFTNGP12.phx.gbl>...
>
> I did that and the generated HTML page has exactly the same
> contents as the file "x.asp" as I orignally posted - this of
> course is what's expected. I already did this with my other
> ASP documents which actually has ASP VBscript code in it,
> and it was generated according to the way I want it.
>
> All the ASP stuff works. It's just the JavaScript that does
> not work. I had the same problem even when running it on
> another machine with PWS on it.
>
> The JavaScript part works When I moved the javascript files
> from c:\inetpub\wwwroot\scripts to c:\inetpub\wwwroot and
> modified the x.asp file accordingly, ie:
>
> <SCRIPT language="JavaScript" src="updated.js" type=
> "text/javascript">
> </SCRIPT>
>
> However, I would like to keep things neat and tidy by
> placing all my external javascript files under the script
> directory.
>
> My belief is that somehow, opening it as an ASP document
> doesn't allow it to recognize that javascript files
> are under the "scripts" directory. All I did so far
> was create a "scripts" directory under c:\inetpub\wwwroot
> and placed js files in it.
>
> Is there anything else I need to configure to let IIS or PWS
> know that javascript files are in a "scripts" subdirectory?



Web Spinner

2004-03-30, 9:30 pm

"Mark Schupp" <mschupp@ielearning.com> wrote in message news:<er$HcInFEHA.1840@TK2MSFTNGP12.phx.gbl>...
> It is the browser that is responsible for retrieving the script file based
> on the HTML code that it is interpreting.
>
> Can you post exactly what you see in "view source"?
>
> --
> Mark Schupp
> Head of Development
> Integrity eLearning
> www.ielearning.com


The view source displayed exactly what was in "x.asp". I didn't want
to place the same code in this thread again.

I found out what the problem was. IIS and PWS comes preconfigured
with a virtual directory called scripts which refers to the
directory "c:\inetpub\scripts". To fix this problem, I either
had to rename my "scripts" directory to something else, or place
all the javascript files under "c:\inetpub\scripts".

Thanks for all your help.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com