...

View Full Version : Pulling data from a .js file into a .html [RESOLVED]



JoWiGo
07-05-2005, 06:54 PM
Hey there, a basic question for you experts out there.

I have a site which organizes information into 'articles', or pages with information within them. On my homepage I am trying to do something very simple - write 'We currently have x articles' where x is the amount of articles.

I currently have a .js file which has:

myArticle = new Array("Article1", "Article2", "Article3")
artCount = myArticle.length

In my main page I have this for my basic code:

<html>
<head>
<title>My site</title>

...

<script src="/member/javascript/articledirectory.js" language="Javascript" type="text/javascript">
</script>

</head>

<body>

...

We currently have
<script>
<!--
document.write(artCount)
// -->
</script>
articles.

...

</body>
</html>


Any clues as to what I am doing wrong?

Burgerking63
07-05-2005, 07:58 PM
Code for your external Javascript file:
function articleCount() {
myArticle = new Array("Article1", "Article2", "Article3")
artCount = myArticle.length;
return artCount;
}HTML Code:
<html>
<head>
<title>My site</title>
...
<script language="Javascript" src="/member/javascript/articledirectory.js"></script>
</head>
<body>
...

We currently have
<script>
var artcountresult=articleCount();
document.write(artcountresult);
</script>
articles.
...

</body>
</html> Hope this helps you out

JoWiGo
07-05-2005, 08:13 PM
Err, unfortunatley it didn't. Running the page with that code returns an error. In front of

var artcountresult=articleCount();
I recieve an error saying that the browser expects an object before var. Any clues?

Burgerking63
07-05-2005, 09:01 PM
The error is very likely a product of your relative reference to your external javascript file. When I tested the code, I had my "articledirectory.js" file in the SAME folder as my HTML document. I just put your URL for the External Javascript file back in. I can think of a few things that would cause this error.

1) You did not copy the code correctly. Make sure you didnt leave something out, or accidently change something somewhere.

2) You did not upload or update the External Javascript file with the new code. If it's already "online", re-upload the new javascript file and make sure that you reference it's location properly. The easiest way to make sure is to just have the External Javascript file in the same folder as your HTML document calling the Javascript. Change the src="/member/javascript/articledirectory.js" to src="articledirectory.js".

The code works fine for me with the "articledirectory.js" file in the same folder as the HTML document calling the file, so I'm guessing the problem is on your end

JoWiGo
07-05-2005, 10:00 PM
I have found out the problem, and it's fixed :). The error was my HTML editor could not process teh script for some reason. However, I uploaded the files and everything worked out fine. Thanks for your patience!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum