PDA

View Full Version : Cannot get .js file to work



ldysmann
04-13-2011, 08:39 PM
Hello all,
I am starting on a final project for an entry level javascript class. The assignment does not seem to difficult but wouldn't you know that I am stuck on the very first part. I am supposed to have the very first line of the page <h1> my name</h1> in an external .js file. I cannot get it to work for some reason.

This is what I have so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web 115 Final Project</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

</head>

<body>
<script type="text/javascript" src="projectjs.js">
</script>
</body>
</html>

This is what the projectjs.js looks like:

<h1>
my name
</h1>


What am I doing wrong?

Thank you for any help!

bluewalrus
04-13-2011, 08:52 PM
That is not JS that is html. You can use PHP's include/require or you could get that through an ajax request. You will need to change that file extension though as it is not js.

ldysmann
04-13-2011, 09:19 PM
I have to use an external javascript file. What has to be done to change it to a .js file.

Beverleyh
04-13-2011, 10:37 PM
If this is your final project, id guess the purpose of the overall task is to recap on the things you've learned in earlier lessons and apply them to a final working scenario.

Try to think back on what has been covered - check your notes and search related topics on the web - hopefully that will get the cogs turning and help you on your way.

Here's a good js resource: http://www.w3schools.com/js/default.asp
Work through a few of the chapters and you'll find your answer :)

I'm a bit wary of forum help and school projects - I work in local government and education and I'm just mindful that asking others to do your class/home work for you (especially on such a well known resource as DD) can have a detrimental effect on your grades. I'm not saying that that's what you're doing but I'm just advising you to be careful of how much help you ask for or the line of questioning you take. This is the reason why my above response is not a straightforward answer and probably also why bluewalrus' reply is leaning towards hints only.