Jump to content

External Javascript


Namal
 Share

Recommended Posts

I used the external Javascipt file to my Html document. But it is not working. Pls explain what is the mistake of my script.This is the Javascript file<script type="text/javascript"> var d = new date() var time = d.getHours() if (time<10) { document.write ("<b>Suba Udesanak</b>") } else if (time>=10 && time<16) { document.write ("<b> Suba Dawask </b>") } else { document.write ("<b>Hello All!</b>") alert ("Hello All) }</script>And this is the Html document.<html><head> <title> My fIrst JavaScript Test</title> <link rel= "stylesheet" type="text/css" href="jsstyle1.css"/></head> <body> <script src="testjs.js"></script> <h1>JS & CSS Practical Test Site</h1> <p>This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. </p>//Therea are another more tags in the body section.. but I think those are not necessary for this.</body></html>Pls help me to solve my problem.

Link to comment
Share on other sites

Why do you need the <script> and </script> in the test.js file???

Link to comment
Share on other sites

This might be more correct, assuming the external javascriptfile is called external.js.

This is the Javascript filefunction Test() {var d = new date()var time = d.getHours()if (time<10){document.write ("<b>Suba Udesanak</b>")}else if (time>=10 && time<16){document.write ("<b> Suba Dawask </b>")}else{document.write ("<b>Hello All!</b>")alert ("Hello All)}}And this is the Html document.<html><head><title> My fIrst JavaScript Test</title><link rel= "stylesheet" type="text/css" href="jsstyle1.css"/><script type="text/javascript" src="external.js"></script></head><body><script>test();</script><h1>JS & CSS Practical Test Site</h1><p>This is a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. Thisis a simple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is asimple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is asimple test site. This is a simple test site. This is a simple test site. This is a simple test site. This is asimple test site. This is a simple test site. This is a simple test site. This is a simple test site.</p>//Therea are another more tags in the body section.. but I think those are not necessary for this.</body></html>

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...