Should be simple!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fussfart
    New Member
    • Jan 2008
    • 3

    Should be simple!

    I'm trying to do something that should be very simple but isn't working! (I also want to do something somewhat more complicated, but that has to wait until I figure out the simple stuff.)

    First, I want to call out a .js file from inside a web page to write some stuff. I've done it before, but it's been a while. I've got it ultra-simplified just to try to get it to work. (Once I've got the bugs out, I'm going to put some real code in the .js file.)

    [HTML]
    This is what's in my web page:

    <div id=content>
    <p>

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

    </p>
    </div>
    [/HTML]
    -------------------------

    Here's the content of outback.js:

    [CODE=javascript]document.writel n("We went to the outback.");[/CODE]

    -------------------------

    When I refresh the web page, nothing appears (except what is actually written inside the page). If I get rid of the reference to outback.js and put the writeln statement inside the <script></script> tags, I get what I want. But I don't want to do that because ... here's the second, advanced question:

    I would like to be able to swap out the text that's inside of those <div></div> tags, based on a function triggered by an onClick event in another div. So, I want to have a little menu and based on what someone clicks ("outback", "daintree", "whitsunday s", etc.), they get different text (and more things to click on) in the "content" div.

    The question is whether this is possible -- I have read that you can't change text in an existing page, but why can't you? You can change images. I've already got my page set up so that when you click different links in one div, you see different images in another div. I just want to modify the swap-out function that changes the images so that it changes the reference to the .js file.

    So,

    First question: Why can't I get the writeln command to execute when it's in the .js file?

    Second question: Can I swap out the contents of a .js file within a given div?

    Thanks for any assistance.
    Last edited by gits; Jan 28 '08, 07:55 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    avoid to use document.write use innerHTML or standard dom-methods to update node contents or change attributes ...

    kind regards

    Comment

    • fussfart
      New Member
      • Jan 2008
      • 3

      #3
      Originally posted by gits
      hi ...

      avoid to use document.write use innerHTML or standard dom-methods to update node contents or change attributes ...

      kind regards
      Thanks, but I'm sorry, I have no idea what that means. Can you give me a little more detail? What is "innerHTML" ? (I'll follow the link and see if I can figure it out myself, but odds are that I can't).

      Thanks again.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        here is an example:

        [HTML]<html>
        <script type="text/javascript">
        function init_page() {
        var node = document.getEle mentById(contai ner);

        node.innerHTML = 'test-content';
        }
        </script>
        <body onload="init_pa ge();">
        <div id="container"> </div>
        </body>
        </html>
        [/HTML]
        here we simply use a div with id 'container' where a function retrieves the reference to it by id and sets innerHTML of it onload of the document. the value to be set has to be a string and could even contain html-markup ...

        kind regards

        Comment

        • fussfart
          New Member
          • Jan 2008
          • 3

          #5
          Originally posted by gits
          here is an example:

          [HTML]<html>
          <script type="text/javascript">
          function init_page() {
          var node = document.getEle mentById(contai ner);

          node.innerHTML = 'test-content';
          }
          </script>
          <body onload="init_pa ge();">
          <div id="container"> </div>
          </body>
          </html>
          [/HTML]
          here we simply use a div with id 'container' where a function retrieves the reference to it by id and sets innerHTML of it onload of the document. the value to be set has to be a string and could even contain html-markup ...

          kind regards

          THANKS, BUT SORRY, DIDN'T WORK. COULD IT BE THAT I'M USING FIREFOX?

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            sorry my bad ... typo :) fix is here, id has to be a string ofcourse:

            [CODE=javascript]var node = document.getEle mentById('conta iner');[/CODE]
            kind regards

            Comment

            Working...