0

I'm new to JavaScript and just want to put my JavaScript code in another file.

This is my html page:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>my badass page</title>
    <script type="text/javascript" scr = "testing.js"></script>//this contains the function I want to call
</head>
<body id="body">
    <button type="button", onclick="showDate()">show the date</button>
</body>
</html>

This is the testing.js file:

function showDate() {
    alert ("this works")
}

I'm assuming that I just make a beginner mistake because it seems really common but I can't figure it out.

1
  • I think you just have to format your code properly. scr? type="button", <= a comma?. Etc... Commented May 17, 2013 at 19:49

3 Answers 3

5

you spelled the 'src' attribute incorrectly on your tag

you spelled it scr, it should be src

this:

<script type="text/javascript" scr = "testing.js"></script>

should be this:

<script type="text/javascript" src = "testing.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

3

change the button to

<button type="button" onclick="showDate()">show the date</button>

and change scr to src

EDIT: source that works:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>my badass page</title>
    <script type="text/javascript" src="testing.js">
    </script>
</head>
<body id="body">
    <button type="button" onclick="showDate();">show the date</button>
</body>
</html>

3 Comments

i just changed that and it still says "Uncaught ReferenceError: showDate is not defined"
You changed scr to src also ? the source works for me, are you also sure that the file is testing.js ? and it is in the same directory ?
ya im going to move the file around, i think the scr was the problem. thank you
0

Quick use of html validator such as http://validator.w3.org/nu/ will uncover lots of problems in your code. Just copy paste and correct the errors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.