Results 1 to 6 of 6

Thread: All text on one page?

  1. #1
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question All text on one page?

    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.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I'm uncertain about what you wanted to achieve, but maybe this could help:
    HTML Code:
    <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>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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>

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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.
    Code:
    <script type="text/javascript" src="your_js_file.js"></script>
    or
    Code:
    <script type="text/javascript">
    //Your JS code goes here
    </script>

  6. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Quote Originally Posted by Eblahmysuper View Post
    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.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •