Click to See Complete Forum and Search --> : external javascript


liquidWizard
08-25-2003, 12:11 PM
c5_leah@hotmail.com
i have 12 items to display in different pages.instead of using 12 pages, i wanna use 2 pages. so i have to use an external javascript.but i don't know how to use it and where to put.
please help me.

pyro
08-25-2003, 12:39 PM
Using JavaScript will not work for the 13% of users who do not browse with JavaScript enabled. Do you have any serverside langagues available? PHP? SSI? You could use them to include the file.

liquidWizard
08-25-2003, 12:48 PM
c5_leah@hotmail.com
thank you.
but the thing is i don't have neither of them.
is there any other ways for me to achieve the same result?:confused:
but any way,thank you all the same.;)

pyro
08-25-2003, 12:51 PM
Find a new host...

Apart from that, using JavaScript to include content is a bad idea... But, if you really want me to tell you, I can.

liquidWizard
08-25-2003, 12:55 PM
you know what? i can't stop smiling.you are so nice.
the thing is i am learning it now. it is a project and have to submit in the next 36hs.
i don't much about the whole thing.
so i think it's easier to use javascipt.
what's your suggestion?

pyro
08-25-2003, 01:18 PM
Here's how you reference an external .js file:

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

And in script.js, you will want to put something like this:

document.write('<p>This is the first line</p>',
'<p>this is the second line</p>',
'<this is the third line</p>',
'<p>etc...</p>');

liquidWizard
08-25-2003, 01:22 PM
oh.i did that.
items.js

var items = [
[1, "Action"],
[2, "Comedy"],
[3, "Drama"]
];
the thing is when i import the items.js and try to browse it.an error message states taht items.js is null or not an object.

pyro
08-25-2003, 01:25 PM
What's the rest of the code look like? Also, are you sure you have the path to the external file correct?

liquidWizard
08-25-2003, 01:29 PM
details03.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www1.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>untitled</title>
<style>
.big { font-size: 20pt; color: red; }
.bigger { font-size: 30pt; color: green; }
</style>
</head>

<body>
<script src="items.js" language="javascript" ></script>
<div class="big">
<script>

var x = location.search;
var y = x.split("=");

for(var i in items){
if (y[1] == items[i][0])
document.write(items[i][1]);
}
</script>

</div>
<hr>
<div class="bigger"> Bla... Bla... Bla.... </div>
</body>
</html>



products.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Untitled Document</title>
<script src="items.js"></script>
<script>
for (var i in items) {
document.writeln("<a href='details03.html?code=" + items[i][0] + "'>");
document.writeln( items[i][1] );
document.writeln("</a>");
document.writeln("<br>");
}
</script>
</head>

<body>
</body>
</html>

what do you mean by the path?

pyro
08-25-2003, 01:32 PM
in <script type="text/javascript" src="items.js"></script> are you sure that items.js exists in the same directory as the html pages?

liquidWizard
08-25-2003, 01:46 PM
oh.i see.but i always have problem with directries.can you tell me how to manage it properly.
thank you.

pyro
08-25-2003, 01:57 PM
You could do this, to be sure it works from wherever you try to access it:

<script type="text/javascript" src="http://www.yourdomain.com/directory/items.js"></script>

liquidWizard
08-25-2003, 02:01 PM
thank you very much.
:D :D :D :D :D :D
thank you.

pyro
08-25-2003, 02:06 PM
You bet... :)