Namal Posted December 20, 2006 Share Posted December 20, 2006 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 More sharing options...
Webworldx Posted December 20, 2006 Share Posted December 20, 2006 Remove the <script..... and </script> lines from the external file Link to comment Share on other sites More sharing options...
vchris Posted December 20, 2006 Share Posted December 20, 2006 Your script tag should probably be in the head section like your link tag. Link to comment Share on other sites More sharing options...
Webworldx Posted December 21, 2006 Share Posted December 21, 2006 Not really, since the code has has in his external file starts writing to the document immediately, but I see what you're saying vchris. Ideally, your external file should be full of functions that you can reference later in your code. Link to comment Share on other sites More sharing options...
PrateekSaxena Posted December 26, 2006 Share Posted December 26, 2006 Why do you need the <script> and </script> in the test.js file??? Link to comment Share on other sites More sharing options...
prb03002 Posted December 28, 2006 Share Posted December 28, 2006 I didn't have <script> or </script> in my External Script but it still wouldn't show up. any suggestions? Link to comment Share on other sites More sharing options...
Procat Posted December 28, 2006 Share Posted December 28, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now