473,507 Members | 12,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Probably A Simple Answer...Text Display...

I can't get this simple crappp!!

Not understanding why my text isn't displaying....

<html><head><title>Problem6</title>

<script type="text/javascript">

var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML(my_message);

</script>
<style type="text/css">

#space{position:absolute; left:10px; top:20px;}

#mybuttons{position:absolute; left:10px; top:75px;}

</style></head>
<body>
<div id="space">
</div>
<div id = "mybuttons">
<input type="button" value="startscroll" id="start">
<input type="button" value="stopscroll" id="stop">
</div>

</body>
</html>

--
Message posted via http://www.webmasterkb.com

Sep 28 '08 #1
11 1299
my_div.innerHTML = my_message;

Tim

"ChuckB via WebmasterKB.com" <u46201@uwewrote in message
news:8ad8274b0aeae@uwe...
>I can't get this simple crappp!!

Not understanding why my text isn't displaying....

<html><head><title>Problem6</title>

<script type="text/javascript">

var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML(my_message);

</script>
<style type="text/css">

#space{position:absolute; left:10px; top:20px;}

#mybuttons{position:absolute; left:10px; top:75px;}

</style></head>
<body>
<div id="space">
</div>
<div id = "mybuttons">
<input type="button" value="startscroll" id="start">
<input type="button" value="stopscroll" id="stop">
</div>

</body>
</html>

--
Message posted via http://www.webmasterkb.com

Sep 28 '08 #2
On 2008-09-28 03:31, Tim Williams wrote:
my_div.innerHTML = my_message;
Are you sure?
There is no element with the id "space" at this point...
- Conrad
Sep 28 '08 #3
Tim Williams wrote:
>my_div.innerHTML = my_message;

Tim
>>I can't get this simple crappp!!
[quoted text clipped - 26 lines]
></body>
</html>
Thanks for the response...tried that...still nothing:

<html><head><title>Problem6</title>

<script type="text/javascript">

var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML=my_message;

</script>
<style type="text/css">

#space{position:absolute; left:10px; top:20px; width:200px; height:50px;
border:1px solid black;}

#mybuttons{position:absolute; left:10px; top:75px;}

</style></head>
<body>
<div id="space">
</div>
<div id = "mybuttons">
<input type="button" value="startscroll" id="start">
<input type="button" value="stopscroll" id="stop">
</div>

</body>
</html>

--
Message posted via http://www.webmasterkb.com

Sep 28 '08 #4
Conrad Lender wrote:
>my_div.innerHTML = my_message;

Are you sure?
There is no element with the id "space" at this point...

- Conrad
There's the div element....

--
Message posted via http://www.webmasterkb.com

Sep 28 '08 #5
On 2008-09-28 03:38, ChuckB via WebmasterKB.com wrote:
>>There is no element with the id "space" at this point...

There's the div element....
Where?
13 lines after you try to access it?

The element has to exist before you can "get it by ID".
- Conrad
Sep 28 '08 #6
Conrad Lender wrote:
>>>There is no element with the id "space" at this point...

There's the div element....

Where?
13 lines after you try to access it?

The element has to exist before you can "get it by ID".

- Conrad
Right here:

<body>
...
<div id="space">
</div>
...
</body>

Am I missing something here?

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 28 '08 #7
ChuckB via WebmasterKB.com:
Conrad Lender wrote:
>>>>There is no element with the id "space" at this point...

There's the div element....

Where?
13 lines after you try to access it?

The element has to exist before you can "get it by ID".

- Conrad

Right here:

<body>
..
<div id="space">
</div>
..
</body>

Am I missing something here?
Your JavaScript is running before the DIV exists. You'll want to wrap your
code into a function and call it once the page has finished loaded. At that
point, the DIV will exist.

<script type="text/javascript">
function doOnload() {
var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML(my_message);
}
</script>

Then you can call this new "doOnload" function when the body has loaded:

<body onload="doOnload()">

Sep 28 '08 #8
On 2008-09-28 04:28, Ben Amada wrote:
Your JavaScript is running before the DIV exists. You'll want to wrap your
code into a function and call it once the page has finished loaded. At that
point, the DIV will exist.
Exactly. But don't forget to fix the other error that Tim pointed out:
function doOnload() {
var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML(my_message);
my_div.innerHTML = my_message;

Strictly speaking, innerHTML isn't even necessary here (and it's a
proprietary property). "mydiv.firstChild.data = my_message" will do just
fine in this simple case.
- Conrad
Sep 28 '08 #9
Conrad Lender wrote:
>Your JavaScript is running before the DIV exists. You'll want to wrap your
code into a function and call it once the page has finished loaded. At that
point, the DIV will exist.

Exactly. But don't forget to fix the other error that Tim pointed out:
>function doOnload() {
var my_message="I love football";
var my_div=document.getElementById("space");
my_div.innerHTML(my_message);

my_div.innerHTML = my_message;

Strictly speaking, innerHTML isn't even necessary here (and it's a
proprietary property). "mydiv.firstChild.data = my_message" will do just
fine in this simple case.

- Conrad
Got it...Lesson learned...always call JavaScript code with a function or else
it will execute before the html appears.

I think that's the lesson....

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 28 '08 #10
On 2008-09-28 04:45, ChuckB via WebmasterKB.com wrote:
Got it...Lesson learned...always call JavaScript code with a function or else
it will execute before the html appears.

I think that's the lesson....
Almost, but not quite. Take this case:

<script type="text/javascript">
function insertMyText () {
var my_div = document.getElementById("space");
my_div.innerHTML = "I love football";
}
insertMyText();
</script>
<div id="space"</div>

That will still give you an error, even though your code was executed in
a function. This however will work fine:

<div id="space"</div>
<script type="text/javascript">
var my_div = document.getElementById("space");
my_div.innerHTML = "I love football";
</script>

The point is that you can only access elements (by ID or otherwise)
after they have been "seen" by the scripting engine (which, like us,
reads the document from top to bottom). To be absolutely sure that all
elements are ready, you can wait until the "load" event. That's what Ben
did when he called his function from the body element's "onload" attribute.
- Conrad
Sep 28 '08 #11
Conrad Lender wrote:
>Got it...Lesson learned...always call JavaScript code with a function or else
it will execute before the html appears.

I think that's the lesson....

Almost, but not quite. Take this case:

<script type="text/javascript">
function insertMyText () {
var my_div = document.getElementById("space");
my_div.innerHTML = "I love football";
}
insertMyText();
</script>
<div id="space"</div>

That will still give you an error, even though your code was executed in
a function. This however will work fine:

<div id="space"</div>
<script type="text/javascript">
var my_div = document.getElementById("space");
my_div.innerHTML = "I love football";
</script>

The point is that you can only access elements (by ID or otherwise)
after they have been "seen" by the scripting engine (which, like us,
reads the document from top to bottom). To be absolutely sure that all
elements are ready, you can wait until the "load" event. That's what Ben
did when he called his function from the body element's "onload" attribute.

- Conrad
Okay, got it...now if you don't mind...please respond to the REAL problem I'm
having on the NEW POST. ..now that I finally got that out the way :-)

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 28 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1441
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
4
1420
by: Tomas Machala | last post by:
Hi, I'm trying to make an application communicating over TCP/IP. It should do only one thing - write received data to console and terminate itself when "exit" received. Problem is that if I send some...
11
1897
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is...
2
1712
by: windsorben | last post by:
I'd like to have an image appear after the student answers each short answer question correctly. I can't seem to get it to work properly. See code below. Thanks! <html> <head>...
3
1883
by: Rangy | last post by:
Hi, I've decided to take the plunge and move from tables to a pure css layout. I still "think" in tables when I do my layouts and I was wondering the following: I have a simple, standard two...
2
3833
by: pvong | last post by:
Newbie learning VB.Net. I have a simple DataReader and I can grab the info. The data is in numeric format like 123.99 and I want a TextBox to just display it just like that. When I use the code...
2
1946
by: stevemtno | last post by:
I've got a problem with a web page I'm working on. I have 4 modules - one of them has 2 tabs, two of them have 4 tabs. When the user clicks on the tabs, the content below them changes. However, when...
9
2232
by: Pygmalion | last post by:
I have found dozen of useful PHP counters on the web. However, nobody is working for my web pages, since administrator does not want to enable the possibility that PHP could be called from HTML. ...
0
4469
rnd me
by: rnd me | last post by:
Purpose: Allows you to create "presets" for text form inputs. "Lightweight and simple to setup, it adds a lot of convenience for ~1kb of code." Only one function, two parameters: First...
0
7110
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...
0
7372
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...
0
7482
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...
0
5623
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,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
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.