wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Problem with javascript include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem with javascript include" Watch "Problem with javascript include" New topic
Author

Problem with javascript include

smitha rai
Ranch Hand

Joined: Aug 15, 2001
Posts: 33
Hi,
I am trying to include a javascript file in the html file. As I execute the html file, it is producing javascript error like 'Object Expected'. I could not trace out where my mistake is. Appreciate if some one help me out in this regard.
Smitha
My code is as under:
=================================================================
test.html
---------
<html>
<head>
<script language="JavaScript" src="/javaScripts/testScript.js"></script>
</head>
<body>
<form>
<input type="button" name="test" value="Test OK" onClick="getOK()">
<input type="button" name="close" value="Close" onClick="closeMe()">
</form>
</body>
</html>
testScript.js
-------------
<SCRIPT LANGUAGE="JavaScript">
function getOK() {
alert("Test is OK");
}
function closeMe() {
window.close();
}
</SCRIPT>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I don't have any way to test it at the moment, but I think the code in your testScript.js automatically has the <SCRIPT> tags are included, so you don't need them (and they're probably getting in the way)
Dave.
smitha rai
Ranch Hand

Joined: Aug 15, 2001
Posts: 33
Thanks Dave,
I did not understand properly. Would you please explain me in detail. If I understand correctly, script tags in the html file is not required. If so, how do I call or import the javascript file into the same?
Smitha
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Firstly, I have to do this:
"smitha_rai",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Now that the official stuff id out of the way
You should try leaving the HTML file alone, and removing the <SCRIPT LANGUAGE="JavaScript"> and </SCRIPT> tags at the top and bottom of the javascript (.js) file.
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with javascript include
 
Similar Threads
not able to redirect to html file from a jsp
Enabling a button
Radio buttons.......
Submit button problem
form submit