PDA

View Full Version : All text on one page?



Eblahmysuper
05-22-2008, 05:08 AM
I know almost nothing about java, but I was wondering if it was possible to have one .js with a bunch of arrays that had document.write(""); codes in them and then call each one into an html page where I needed them... if that makes sence.

i.e If I have an "array 1" and want it to say "hello" then in the html I could put, script src="array 1", and it would put "hello" there.

and if that is possible how would I make multiple "arrays" and link them in the html? Like script src="array 2", and it would put "goodbye" there etc..?

Im soo confused any help would be greatly appreciated. :confused:

rangana
05-22-2008, 05:44 AM
I'm uncertain about what you wanted to achieve, but maybe this could help:


<script type="text/javascript">
window.onload=function()
{
var c1='Hello', // Content1 contents
c2='GoodBye', // Content2 contents
c3='Whatever', // Content3 contents
c4='DynamicDrive', // Content4 contents
c5='Lorem Ipsum', // Content5 contents
content1=document.getElementById('content1'),
content2=document.getElementById('content2'),
content3=document.getElementById('content3'),
content4=document.getElementById('content4'),
content5=document.getElementById('content5');
content1.innerHTML=c1;
content2.innerHTML=c2;
content3.innerHTML=c3;
content4.innerHTML=c4;
content5.innerHTML=c5;
}
</script>
<div id="content1"></div>
<div id="content2"></div>
<div id="content3"></div>
<div id="content4"></div>
<div id="content5"></div>
<div id="content6"></div>
<div id="content7"></div>

djr33
05-22-2008, 07:30 AM
And by the way, I don't mean to sound picky, but "Java" and "Javascript" are two very different languages-- and you should know that. You've fallen victim to the marketing, but they're only related in name. They come from different backgrounds entirely.

Eblahmysuper
05-23-2008, 02:28 AM
I found some one that knew JavaSCRIPT...lol... in one of my classes. Just for if someone else needed to do what I was doing here is the javascript followed by what you would need to put in the html.

Java:
var name_one = "Welcome";
var name_two = "How are you?";
var name_three = "Good Bye!";

function writeStatus(apt)
{
document.write(apt);
}

HTML:
<html>
<head>
<script language="JavaScript" src="SorceJavascript.js"></script>
</head>
<body>
<script>
writeStatus(name_one);
</script>
to my webpage!
</body>
</html>

codeexploiter
05-23-2008, 03:52 AM
1. When you use document.write make sure that those statements executes before the page loads completes otherwise these statements will replace the content of the page with whatever it writes into the page.

2. The language attribute of script tag is deprecated now, it is better if you use type attribute instead of language attribute in the following manner.

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

<script type="text/javascript">
//Your JS code goes here
</script>

rangana
05-23-2008, 05:46 AM
I found some one that knew JavaSCRIPT...lol... in one of my classes. Just for if someone else needed to do what I was doing here is the javascript followed by what you would need to put in the html.

Java:
var name_one = "Welcome";
var name_two = "How are you?";
var name_three = "Good Bye!";

function writeStatus(apt)
{
document.write(apt);
}

HTML:
<html>
<head>
<script language="JavaScript" src="SorceJavascript.js"></script>
</head>
<body>
<script>
writeStatus(name_one);
</script>
to my webpage!
</body>
</html>

Why?...Does the code on post#2 does'nt works as this?.

Anyway, glad you've figured this out, just slight ammendment pointed by codeexploiter.