SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML file not communicating with JavaScript File (traditional event handler issue?)

    Hey all,

    I've created various projects on websites like codeacademy and codepen and decided to transfer my code into an external text editor (Notepad++).

    When I run the HTML files in my browser, the CSS files works fine but the JavaScript files do not work (unless I use inline event handlers). I've linked the files in the HTML document, made sure they all sit in the same folder, and have run through the code for an possible syntax mistakes.

    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<link rel="stylesheet" href="test.css"/>
    	<script src="test.js"></script>
    </head>

    I feel as though I am missing something simple within the JS file because whenever I use inline event handlers, the JavaScript files run fine. When I use traditional event handlers, the file does not work at all.

    Any ideas about what I might be doing wrong?

    Thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,819
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by codeBread View Post
    I've linked the files in the HTML document, made sure they all sit in the same folder, and have run through the code for an possible syntax mistakes.

    Any ideas about what I might be doing wrong?

    Thanks
    You are attaching the JavaScript in the wrong place.

    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<link rel="stylesheet" href="test.css"/>
    </head>
    <body>
    
    <script src="test.js"></script></body>
    </html>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh wow, thank you very much! I had a feeling it was something as trivial as that.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •