Jump to content

External script


prb03002
 Share

Recommended Posts

I just started learning JavaScript and was trying to see how the external script works. Unfortunately, I was unsuccessful :) . I created a JavaScript document and tried to use that as an external script in a HTML file but it doesn't print the document out. Any suggestions? Note: My location for the document is correct

Link to comment
Share on other sites

Make sure that there aren't any html tags (including <script></script>) in your external javascript file and make sure that you remember to close your script element with a separate </script> tag.This works:

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

This doesn't:

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

If this doesn't help, you'll probably have to post your code. :)

Link to comment
Share on other sites

Thats what I had before but it didn't show up. This is the code for the HTML file:

<html><head><title>external</title></head><body><script src="jstext.js"></script><p>The actual script is in an external script file called "jstext.js".</p></body></html>

and the code to the javascript document is:

 My name is Prateek.  I am learning how to use JavaScript.

Link to comment
Share on other sites

and the code to the javascript document is:
 My name is Prateek.  I am learning how to use JavaScript.

If that is actually what you had in your javascript file, the reason it's not displaying is because that isn't javascript. Javascript would look more like this:
document.write("My name is Prateek.  I am learning how to use JavaScript.");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...