PDA

View Full Version : Trouble including .js files in html


thall411
02-21-2006, 05:20 PM
This is an example of an html page I am trying to create.

When it is run "as is" (with the function subCall in a .js file in the same directory as the .html file, only the first alert shows. But, comment that line out and uncomment the function definition, it works file.

Of course, this works locally, but when I put it onto the server, it doesn't.

I'm new to scripting so I'm hoping there is an easy fix to this.

BTW - this is on http://www.teresahall411.com/example.html

Thanks - Teresa

<HTML>
<HEAD>

<script language='JavaScript' type='text/JavaScript' src='example.js'></script>

<SCRIPT language="javascript">

<!-- function subCall(){ alert('in subCall') ; } -->

function init() {
alert('in init') ;
subCall() ;
alert('after call') ;
}
</SCRIPT>
</HEAD>

<BODY ONLOAD='init()'>
<FORM NAME='frmChooseDrivers'>
<TABLE ID='commentTbl'></TABLE>
</FORM> </BODY>

</HTML>

Here is the example.js file:

function subCall() {
alert('in subCall') ;
}

arnyinc
02-21-2006, 06:11 PM
That is not what is in your example.js file. It is showing:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Menu for /example.js</title>
</head><body>
<h1>Menu for /example.js</h1>
<hr>

<pre> <a href="http://teresahall411.com/subCall()">subCall()</a></pre>
<pre> <a href="http://teresahall411.com/alert('in">alert('in</a></pre>


</body>
</html>


Are you using an IDE like Dreamweaver or FrontPage? Something is tinkering with your js file.

If you open your example.js file in notepad, all it should show is:


function subCall() {
alert('in subCall') ;
}

thall411
02-21-2006, 06:18 PM
Yeah, I found this out. When i look at the file with a text editor, it looks fine. It's just when you look at it with a browser. I changed the extension to .txt and the browser works fine.

Am I supposed to put something at the beginning of the .js file?

Thanks

thall411
02-21-2006, 06:19 PM
I'm not sure what an IDE is, but the file was created with notepad.