473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Should be simple!

3 New Member
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", "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.
Jan 27 '08 #1
5 1617
gits
5,390 Recognized Expert Moderator Expert
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
fussfart
3 New Member
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 Recognized Expert Moderator Expert
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
Jan 28 '08 #4
fussfart
3 New Member
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?
Jan 29 '08 #5
gits
5,390 Recognized Expert Moderator Expert
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

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

Similar topics

303
17682
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
22
1736
by: Alexander Schmolck | last post by:
Two smallish things that have been bugging me; I'm not sure whether they're actually broken or not, but anyway here it goes: 1. ``os.system`` (and co): Shouldn't ``os.system``'s signature really be ``os.system(cmd, arg1, arg2,...)`` rather than ``os.system(some_string)``? Otherwise ``some_string`` almost certainly will be constructed by something along the lines of ``os.system('convert %s %s' % (infile, outfile))`` which of course is...
124
4949
by: 43 | last post by:
how come m$Office isn't written in .net? how come Open Office isn't written in j2ee? how come dbms systems aren't written in either? how come browsers aren't written in either? how come RealPlayer, MediaPlayer and all applications that need speed are written in c++ ? (except for
36
4107
by: Jack Hughes | last post by:
This argument has come up two or three times lately. We have a web standards document at our company that say "Use valid HTML 4; We don't recommend switching to DIV-based CSS-P for layout just yet though, tables are a lot easier." That's because we have a lot of developers who aren't ready to move to CSS-P and DIVs just yet. But I'm being told our policies were contradictory. If we're going to
5
4206
by: AES/newspost | last post by:
I've just re-scanned most of the 60+ posts in the "Frames are Evil" thread, and my question, as the admittedly and permanently amateur creator and maintainer of a simple site, is: Using only elementary HTML and CSS code, how do I create a simple "framelike" main page without being evil? where definition of "how" is --Example of a skeleton HTML template
175
8862
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
21
2856
by: TAM | last post by:
Hi, I read that ASP.NET uses VB.NET instead of VBScript. I also read that ASP.NET is a subset of VB.NET. So if I learn VB.NET first then do I have the knowledge for programming ASP.NET applications or do I need to learn both VB.NET and ASP.NET. Thank you. TAM
10
1800
by: Solo.Wolve | last post by:
Well,I read <c primer plusbefore,and I just got a primary conclusion about c. Can somebody show me some books to read and something to do ? I study c myself.btw,I am not a student, Thanks.
8
2216
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - When should I use eval? ----------------------------------------------------------------------- The ` eval() ` function should _only_ be used when it is necessary to evaluate a string supplied or composed at run-time; the string can be anything from a simple (but unpredictable) expression such as 12*2.54 to a substantial piece of javascript code. The `...
4
2156
by: sinbad | last post by:
how can i write a program, which should accept input as NAME of a variable in the program and print it's value.Is this possible. for example. int main () { int x,y,z; x = 10; y = 20; z = 30;
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.