Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2004, 02:32 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default function in linked js file 'is not defined'

Hi:

I'm trying to set up an ecommerce site.

I've set up a new web server on my Win2000 machine, something I've never had a need to do before. I am doing this because I am in a remote location and none of the company's other machines are available to me to use as a development environment.

I've run into a snag in that I can't seem to get linked javascript files to be recognized by my web pages. If I move the web pages to another web server, they seem to work fine. On my machine, I get 'fred is not defined' in the Javascript console (Netscape).

If I embed the 'fred' function in the <head> section, and attach is to the onchange event of a text box, it works fine.

<script language="javascript">
<!--

function fred()

{
    alert("fred");
}

-->
</script>


If I embed the javascript file in the <head> section using 'include' and pointing to the javascript file, it works fine.


<script language="javascript">



</script>



But if I use

<script language="javascript" src="./controlfunctions.js" type="text/javascript"></script>

I'm guessing it's a configuration issue, but I can't find what it might be.

If it's helpful, here is a sample of how it's attached to the event

<td class=copysmall><input type=text name=item1qty id=item1qty value=0 style=font-size:10px; size=3 maxlength=3 onchange='fred()'></td>

Any help is greatly appreciated.

Thanks for your time.

JK
 
Old May 6th, 2004, 02:38 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Place this line in the .js file to test it:

alert();

I assume it won't work. Maybe you need to refresh. Check here to see what I'm talking about.

Until this gets fixed you can just do that include virtual, if it doesn't get in the way.

HTH,

Snib

<><
 
Old May 6th, 2004, 06:35 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, what I'm pretty sure of is that the file is not being found for some reason.

There is an error coming up in the Javascript Console that reads:

Error: syntax error
Source File: http://jkkpcnew/chronologystore/fred.js
Line: 1
Source Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

The source file is a link, which, if you click on it, produces:


----------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html dir=ltr>

<head>
<style>
a:link {font:8pt/11pt verdana; color:FF0000}
a:visited {font:8pt/11pt verdana; color:#4e4e4e}
</style>

<meta NAME="ROBOTS" CONTENT="NOINDEX">

<title>The page cannot be found</title>

<meta HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
</head>

<script>
function Homepage(){
<!--
// in real bits, urls get returned to our script like this:
// res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm

    //For testing use DocURL = "res://shdocvw.dll/http_404.htm#ht


-------------------------------------------------------

which you may or may not recognize as the ASP Error 404 page, file not found.

So, when loading the requested page, it's looking for 'fred.js', not finding it, grabbing the 'ASP Error 404' page and squawking about the DOCTYPE line in that file. Squawking because it's finding an HTML file and not a Javascript text file?

I'm confused. I'm pretty sure this is a configuration issue of some sort I'm poking around the documentation, but I really don't know where to begin to look.

Thanks,

JK
 
Old May 6th, 2004, 06:38 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

What about the '.' before the '/controlfunctions.js'? Or am I missing something obvious (again)?

Snib

<><
 
Old May 7th, 2004, 09:04 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Snib:

Well, the dot (.) before the '/controlfunctions.js' should only mean 'current directory', just like two dots (..) would represent the parent directory.

For now, I've given up on finding the reason for the problem and I'm accessing the javascript functions by using the #include workaround.

Sure would like to know what the story is though.

Thanks,
JK





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run a .js file from a javascript function sbkumar Javascript How-To 1 July 11th, 2008 11:12 AM
To include a js file into another js file jdang67 Javascript 4 February 28th, 2008 03:32 AM
error function not defined Dj Kat Ajax 6 March 6th, 2006 12:02 PM
User Defined Function niravp SQL Server 2000 7 November 29th, 2004 02:18 PM
Sub or Function Not Defined Olivia54 Access VBA 4 July 10th, 2004 01:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.