Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange effects with <DIV>

Status
Not open for further replies.

Dragonfish

Programmer
Apr 25, 2001
62
UG
I´m trying an exercise with <DIV> tags an getting some strange effects. The basic idea is to write no body-HTML-code at all. When opening the HTML-file with IE the are no error messages and the alert-box is loaded but the &quot;DIV-boxes&quot; are only opened after I press IE´s refresh button (IE5). Using NN4 the &quot;DIV-boxes&quot; are loaded but then I get a javascript error message &quot;WriteToDivObjects is not defined.&quot; and the alert-box is not loaded. Can anybody tell me what´s going on - THANKS. Oh and just to round up the problem - can anybody tell me how to write text into the &quot;DIV-boxes&quot; (document.write....DIV ID=...Hallo World.... ). I need the exact syntax. You´d be amazed, although there are gigabytes of doc on the web I´ve never found the syntax for this basic function /different for IE and NN). Here are the files:

<html>
<head>
<title>hauptfenster</title>
<meta name=&quot;author&quot; content=&quot;me&quot;>
<script language=&quot;JavaScript&quot; src=&quot;main6.js&quot; type=&quot;text/javascript&quot;></script>
</head>
<body text=&quot;#FF0000&quot; bgcolor=&quot;#FACB85&quot; onLoad=&quot;TestWrite()&quot;>

</body>
</html>

And the external main6.js file:

function TestWrite()
{
DefineDivObjects();
WriteToDivObjects();
}

function DefineDivObjects()
{
document.write(&quot;<DIV ID='ParentOneDiv' STYLE='position: absolute; border: none; left: 10px; top: 50px; width: 400px; height: 200px; background-color :#FFFFFF; layer-background-color:#FFFFFF;'></DIV>&quot;);
document.write(&quot;<DIV ID='ParentTwoDiv' STYLE='position: absolute; border: none; left: 420px; top: 50px; width: 400px; height: 200px; background-color :#FFFFFF; layer-background-color:#FFFFFF;'></DIV>&quot;);
}

function WriteToDivObjects()
{
alert(&quot;Function ok.&quot;);
}

Thanks again DavidinGermany
 
to write to a div:
in ie4+ and ns6+:
document.all[divId].innerHTML+='an <B>h</B>tml string';

in ns4.7+:
document.layers[divId].open();
document.layers[divId].write();
document.layers[divId].close();

(at least I think that is the right syntax)

as for the printing of a page, can you post the errors Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Thanks Robert for the reply,

In IE5 I´m still getting the following error message:

Zeile: 35
Zeichen: 3
Fehler: 'ParentOneDiv' is not defined

In NS4.75 I´m still getting the following error message:

JavaScript Error: file:///C|/Eigene
Dateien/ line 9:

WriteToNNDivObjects is not defined.

So the objacts arn´t defined - but ?????? My script now looks like this - I took the &quot;&quot; out of the [ParentOneDiv] but other than that nothings changed. I get the feeling I´m making a fundamental mistake but I´m surrounded by so many trees here I can´t see the forest. I´d be gratefull if you´d take anothe look - what a way to spend a Sunday, many thanks David

function TestWrite()
{
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

if (ns4)
{
DefineDivObjects();
WriteToNNDivObjects();
}
else if (ie4)
{
DefineDivObjects();
WriteToIEDivObjects();
}
}

function DefineDivObjects()
{
document.write(&quot;<DIV ID='ParentOneDiv' STYLE='position: absolute; border: none; left: 10px; top: 50px; width: 400px; height: 200px; background-color :#FFFFFF; layer-background-color:#FFFFFF;'></DIV>&quot;);
document.write(&quot;<DIV ID='ParentTwoDiv' STYLE='position: absolute; border: none; left: 420px; top: 50px; width: 400px; height: 200px; background-color :#FFFFFF; layer-background-color:#FFFFFF;'></DIV>&quot;);
}

function WriteToNNDivObjects()
{
document.layers[ParentOneDiv].open();
document.layers[ParentOneDiv].write(&quot;my text here&quot;);
document.layers[ParentOneDiv].close();
alert(&quot;Function ok.&quot;);
}

function WriteToIEDivObjects()
{
document.all[ParentOneDiv].innerHTML+='an <B>h</B>tml string';
alert(&quot;Function ok.&quot;);
}
 
Ok, here is the problem:

after a page is loaded, and you call the document.write function, it clears out everything from the previous page and starts a new one. so, modify your document.write functions to say document.body.innerHTML+='<div...>';

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top