470,594 Members | 1,134 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

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:

Expand|Select|Wrap|Line Numbers
  1. document.writeln("We went to the outback.");
-------------------------

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", "whitsundays", 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.
Jan 27 '08 #1
5 1355
gits
5,390 Expert Mod 4TB
hi ...

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

kind regards
Jan 28 '08 #2
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.
Jan 28 '08 #3
gits
5,390 Expert Mod 4TB
here is an example:

[HTML]<html>
<script type="text/javascript">
function init_page() {
var node = document.getElementById(container);

node.innerHTML = 'test-content';
}
</script>
<body onload="init_page();">
<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
Jan 28 '08 #4
here is an example:

[HTML]<html>
<script type="text/javascript">
function init_page() {
var node = document.getElementById(container);

node.innerHTML = 'test-content';
}
</script>
<body onload="init_page();">
<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?
Jan 29 '08 #5
gits
5,390 Expert Mod 4TB
sorry my bad ... typo :) fix is here, id has to be a string ofcourse:

Expand|Select|Wrap|Line Numbers
  1. var node = document.getElementById('container');
kind regards
Jan 29 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

303 posts views Thread by mike420 | last post: by
22 posts views Thread by Alexander Schmolck | last post: by
5 posts views Thread by AES/newspost | last post: by
21 posts views Thread by TAM | last post: by
10 posts views Thread by Solo.Wolve | last post: by
8 posts views Thread by FAQ server | last post: by
4 posts views Thread by sinbad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.