...

View Full Version : document.write problem



JAVAEOC
02-01-2004, 06:38 AM
thise COMPLEX code does not work

<html><head><script>
var testvar="shishsihsi";
function Write(){document.write(testvar)}
</script></head>
<body onClick="Write()">test test test</body>

i know very big (:rolleyes: )

however it delets the test test test when it writes the testvar

whats wrong and how do i fix it?

thanks for any help

Dennis
02-01-2004, 09:52 AM
the document.write method writes something on the page. If you use it when the page has been completely loaded, it deletes all and writes only that sentence...

coothead
02-01-2004, 10:04 AM
Hi there JAVAEOC,

..........so use 'innerHTML'
like this....
<html>
<head>
<script type="text/javascript">
var testvar="shishsihsi";
function Write()
{
document.getElementById("foo").innerHTML=testvar;
}
</script>
</head>
<body onclick="Write();">
<p>test test test</p>
<div id="foo"></div>
</body>
<html>

This works fine except for 'Opera' where you have to click
within the 'p' for it to function :rolleyes:

c:cool::cool:thead

JAVAEOC
02-01-2004, 03:04 PM
cool thx.

deathmill
02-02-2004, 05:31 PM
hi,

how can this be updated so that I can use multiple document.write? I've tried:

<script type="text/javascript">
document.write="a";
document.write="b";
function Write()
{
document.getElementById("foo").innerHTML=document.write;
}
</script>

It works but seems to write the last one ie. b

thanks,

Death = $Mill

Willy Duitt
02-02-2004, 05:49 PM
Originally posted by deathmill
hi,

how can this be updated so that I can use multiple document.write? I've tried:

<script type="text/javascript">
document.write="a";
document.write="b";
function Write()
{
document.getElementById("foo").innerHTML=document.write;
}
</script>

It works but seems to write the last one ie. b

thanks,

Death = $Mill

Use the + operator to concatenate the two strings.

eg:

<script type="text/javascript">
document.write="a";
document.write+="b";
function Write()
{
document.getElementById("foo").innerHTML=document.write;
}
</script>

.....Willy

BTW: document.write is not an appropriate variable name.
You need to change that to something which is not a reserved word or method.

oldcrazylegs
02-28-2004, 06:06 PM
Instead of writing document.write my self I use this easy converter at about.com. All you do is copy and paste your HTML source into it and click on CONVERT. It is many times faster.

http://javascript.about.com/library/tools/bldocwriter.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum