• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Problem with javascript include

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic