473,574 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.write( ) in the middle of a document?

Hi,

does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL

Sep 19 '05 #1
25 3453
jullag wrote on 19 sep 2005 in comp.lang.javas cript:
Hi,

does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL


document.write( ) can be used anywhere in a html document, but it should
only be used before the document is fully loaded and an implicit
document.close( ) is issued.

Any next document.write( ) will implicidly do a document.open() , thereby
destroying the whole page inclusive of any onpage javascript.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 19 '05 #2
jullag wrote:
does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL


document.getEle mentById("MyDiv ").innerHTML="w hatever"
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 19 '05 #3
Dr Clue wrote:
jullag wrote:
does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL



document.getEle mentById("MyDiv ").innerHTML="w hatever"


I'm also having a document.write( ) problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write( ) executes.. thank you...

Frances
Sep 19 '05 #4
Lee
Frances said:

Dr Clue wrote:
jullag wrote:
does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL



document.getEle mentById("MyDiv ").innerHTML="w hatever"


I'm also having a document.write( ) problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write () executes.. thank you...


That's exactly what document.write( ) is supposed to do.
The first call to document.write( ) after the page has been displayed
generates a call to document.open() , to re-open it for writing.
document.open() , in turn, always calls document.clear( );

Sep 19 '05 #5

jullag wrote:
Hi,

does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL


Hi JL,

Off the top of my head, I can think of 2 ways.

Suppose you had an element:

<div id = "mydiv"></div>

and you wanted to insert text in between the div tag. You can do the
following:

var div = document.getEle mentById("mydiv ");
var text = document.create TextNode("my text");
div.appendChild (text);

OR

document.getEle mentById("mydiv ").innerHTM L = "my text";

Hope this helps. :)

Sep 19 '05 #6
JRS: In article <43************ *********@news. sunsite.dk>, dated Mon,
19 Sep 2005 13:48:51, seen in news:comp.lang. javascript, Frances
<fd***@yahoo.co m> posted :
Dr Clue wrote:
jullag wrote:
does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
document.getEle mentById("MyDiv ").innerHTML="w hatever"


I'm also having a document.write( ) problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.write () executes.. thank you...


Both respondents, and the OP, should read the newsgroup FAQ.

To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getEl ementById) {
document.getEle mentById = function(id) { return document.all[id] } }

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 19 '05 #7
Dr John Stockton said the following on 9/19/2005 4:20 PM:
JRS: In article <43************ *********@news. sunsite.dk>, dated Mon,
19 Sep 2005 13:48:51, seen in news:comp.lang. javascript, Frances
<fd***@yahoo.co m> posted :
Dr Clue wrote:
jullag wrote:
does anyone know of any javascript method that does the same job as
document.wr ite(), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
document.get ElementById("My Div").innerHTML ="whatever"


I'm also having a document.write( ) problem.. document.write is
generated dynamically, and everything else in the page disappears when
document.writ e() executes.. thank you...

Both respondents, and the OP, should read the newsgroup FAQ.

To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getEl ementById) {
document.getEle mentById = function(id) { return document.all[id] } }


And that it is only needed for a browser that is almost 10 years old?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 19 '05 #8

jullag wrote:
Hi,

does anyone know of any javascript method that does the same job as
document.write( ), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL


It is interesting that document.write is taboo in xhtml 1.1 served
correctly as application/xhtml+xml. Most of the recent browsers can
handle this mime type, but not the badly outmoded IE6(you can use a php
include at the very top of the page to automatically rewrite the code
as html 4.01 strict if you run into an outmoded browser). When you
write in xhtml 1.1 and serve as the correct mentioned mime type, modern
browsers including Opera and the Mozilla family(Mozilla, Firefox,
Netscape) become extremely strict and parse the code as xml. One reason
a document.write can not be allowed, is there is no telling what it
might write including tags that are not closed or xml forbidden
characters. Thus document.write can not be allowed. If you use
document.write, even in an external script, the page will not display
and you may get a xml parse error message from the browser. I often use
server-side php script to get around this problem. For example, my
60000 year perpetual calendar needs hundreds of divisions to write a
calendar for a full year. This was done with javascript using a
document.write at the bottom of a nest of 4 "for" loops to write all of
the divisions. This all had to go on conversion to xhtml 1.1 served
with the proper mime type. One enters the desired year, which is sent
to the server. Then the server uses php to write the code for the
calendar for the selected year, which produces hundreds of divisions.
This code is then downloaded to the browser, and the xml parser is
pleased because it can check all of the computed divisions for closing
tags, xml forbidden characters, and such. Many are kicking and
screaming about using true xhtml, but it can be done now in most cases
with automatic conversion to html 4.01 strict for outmoded browsers. If
one only considered PCs, there might be little justification for xhtml
and xml purity. However there are now a large number of computing
devices out there in addition to PCs. To allow the many devices to
exchange information, they all need to conform to xml or some other
standard they they all can understand. For now, xml seems to be the
best common language for most devices that we have.

Sep 20 '05 #9
JRS: In article <49************ ********@comcas t.com>, dated Mon, 19 Sep
2005 18:58:42, seen in news:comp.lang. javascript, Randy Webb
<Hi************ @aol.com> posted :
Dr John Stockton said the following on 9/19/2005 4:20 PM:
To be clueful, recommendation of getElementByID should be accompanied by
noting that it does not work on all browsers (see FAQ) and that it can
be emulated well enough for some of the others.

if (document.all && !document.getEl ementById) {
document.getEle mentById = function(id) { return document.all[id] } }


And that it is only needed for a browser that is almost 10 years old?


You exaggerate : the system age is less than three-quarters of that.

Not everyone uses the latest systems (vulnerable to the latest malware).
Indeed, you yourself are using, AIUI, an out-of-date newsreader.

<QUOTE>
Can

User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707)
X-Accept-Language: en-us, en

be set to properly unambiguous date-stamps, rather than such as

9/1/2005 6:13 PM meaning Sep 1st

and, if so, how?


I don't think it's alterable, but there have been several upgrades
since then. Version 1.0.2 gives the proper dd mmm yyyy hh:mm:ss format.

</QUOTE>

Of course, even that format is not as proper as it would be if it
followed ISO 8601.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 20 '05 #10

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

Similar topics

1
2862
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>"); document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso </OPTION>"); document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
3
9821
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle of the screen that initially comes up with a gif image of a house: <!-- start "house" layer definition for center of screen --> <DIV id="house"...
2
2374
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple...
10
13666
by: Rithish | last post by:
I want to emulate paging in an HTML document. something like, ------------------------- | | | <DIV> | | | | <TABLE></TABLE> | | | | <TABLE></TABLE> | | |
4
2969
by: Charles Crume | last post by:
Hello all; I have a web page that displays a blank gif for about 2 seconds, then displays an animated gif image, then, after the animation plays, I want to display a link so the user can click on it and go to another page. I am fairly new to javascript and came up with the following code: ----------------------- <p align="center"><img...
4
1433
by: PHP2 | last post by:
how I can create frame inside in total middle of document with? I have one htnl and I need html page totaly in middle..
12
3322
by: Radek Maciaszek | last post by:
Hi It's very interesting problem. I couldn't even find any inforamtion about it on the google. I think that the best way of explain will be this simple example: <html> <body> <script language="JavaScript" type="text/javascript" src="write.js"></script>
5
2960
by: SuneR | last post by:
Hi, I am having problems figuring out how to make Firefox behave, and output the HTML I want it to output. The thing I want done is actually quite simple. I have a <labeltag, and inside it, I have a script tag, that document.write's some HTML. Like this:
5
3997
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
0
7801
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...
0
7719
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...
0
8044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8229
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...
0
8096
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...
0
5299
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...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1055
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.