473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Can JavaScript place HTML code into Div...?

Hi,

What I like to know is if it is possible to have a JavaScript writing code
into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
.......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....
<div id=div1 name=div1>
</div>
....

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

...so it would display the word "hello" in the area taken up by the <DIV
id=div1 name=div1>
I understand you can change attributes/properties like the value of a text
field but what about this scenario???
TIA,

Tom
Jul 23 '05 #1
6 1204
Tom Szabo wrote on 16 nov 2004 in comp.lang.javascript:
What I like to know is if it is possible to have a JavaScript writing
code into a DIV section, that is say during load or on a certain event
in the same page it would insert the word "hello"

----------------
......
<script>
function insert_hello(){
document.getElementById("div1").innerHTML="Hello"
}
</script>

<body onload="insert_hello()"....
<div id=div1 name=div1>
</div>
...

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

..so it would display the word "hello" in the area taken up by the
<DIV id=div1 name=div1>
I understand you can change attributes/properties like the value of a
text field but what about this scenario???



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Thanks, it does exactly what I needed,

Thanks again,

Tom
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Tom Szabo wrote on 16 nov 2004 in comp.lang.javascript:
What I like to know is if it is possible to have a JavaScript writing
code into a DIV section, that is say during load or on a certain event
in the same page it would insert the word "hello"

----------------
......
<script>
function insert_hello(){


document.getElementById("div1").innerHTML="Hello"
}
</script>

<body onload="insert_hello()"....
<div id=div1 name=div1>
</div>
...

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

..so it would display the word "hello" in the area taken up by the
<DIV id=div1 name=div1>
I understand you can change attributes/properties like the value of a
text field but what about this scenario???



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #3
JRS: In article <41******@dnews.tpgi.com.au>, dated Wed, 17 Nov 2004
02:50:20, seen in news:comp.lang.javascript, Tom Szabo
<to*@intersoft.net.au> posted :

Please place responses after trimmed quotes - see newsgroup FAQ, 2.3.
Thanks, it does exactly what I needed,
In most but not all browsers - see FAQ, 4.15.
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...

document.getElementById("div1").innerHTML="Hello"


--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 23 '05 #4
Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:
document.getElementById("div1").innerHTML="Hello"

Thanks, it does exactly what I needed,

In most but not all browsers - see FAQ, 4.15.


While this is true, John,
the OP clearly shows a to be a newbee,
and a complete solution would scare the OP off,
which is worse IMHO, than the incompliance.

btw: Having javascript switched off could be
a far more probable problem,
than having a innerHTML incompliant browser.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #5
JRS: In article <Xn********************@194.109.133.29>, dated Wed, 17
Nov 2004 08:25:39, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:
document.getElementById("div1").innerHTML="Hello"
Thanks, it does exactly what I needed,

In most but not all browsers - see FAQ, 4.15.


While this is true, John,
the OP clearly shows a to be a newbee,
and a complete solution would scare the OP off,
which is worse IMHO, than the incompliance.

btw: Having javascript switched off could be
a far more probable problem,
than having a innerHTML incompliant browser.


It is not for us to decide what the reader is allowed to know; it is for
the reader to decide what he needs to support, knowing that the solution
you gave is not universal. A reference to the FAQ achieves that
warning.

So does "Older browsers may not know getElementById; it can be provided
if needed by
if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id] } } // "

// (which seems OK to me, and works in IE4.)

Moreover, since he *is* asking about something which the FAQ answers,
then he should in any case be referred to the FAQ; he may very well find
there answers to future questions.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6
Dr John Stockton wrote on 17 nov 2004 in comp.lang.javascript:
Moreover, since he *is* asking about something which the FAQ answers,
then he should in any case be referred to the FAQ;
"should"?

I don't think so, John.

A straight answer is not against netiquette, even if there is a NG-FAQ.

I would agree on "could".
he may very well find there answers to future questions.


Undoubtedly, he may.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #7

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

Similar topics

3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
2
by: Jeannie | last post by:
I have a popup window which is a slideshow of about 7 images. When the popup window loads, the first image is present and then the viewer can select next or previous to scroll through the rest of...
5
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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...

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.