Page 1 of 1

JavaScript; document.write()

Posted: Thu Jun 27, 2002 12:47 pm
by Johnm
Hi all,
When I use the document.write() function, the output of the function is written to a white screen, I want it to go to the same screen below the existing table. Any ideas?
Thanks,
Direwolf

Posted: Thu Jun 27, 2002 8:50 pm
by volka

Posted: Fri Jul 12, 2002 3:15 am
by gnu2php
:arrow: See also http://developer.netscape.com/docs/manu ... /index.htm

I had the same problem a while back. The problem is that the webpage can't be altered once it's displayed on the screen--unless you use DHTML (Dynamic HTML).

The hardest part of DHTML is making it work in both IE and Netscape. They use different methods for changing the content of the webpage.

Here's something to get you started:

Code: Select all

<input type="button" onClick="hello_world()" value="Click me"><br><br>


<span id="preview_text_ie"></span>
<layer id="preview_text_ns"></layer>


<script language="JavaScript">
<!--
function hello_world()
&#123;
	var ie = document.all && (navigator.appVersion.indexOf("Mac") == -1);
	var ns = document.layers;

	if (ie) // Using IE
	&#123;
		document.all&#1111;"preview_text_ie"].innerHTML = "Hello World";
	&#125;
	else if (ns) // Using netscape
	&#123;
		document.preview_text_ns.document.write("Hello World");
		document.preview_text_ns.document.close();
	&#125;
&#125;
//-->
</script>

Posted: Sun Jul 14, 2002 6:13 pm
by georgec
gnu2php,
In your example it implies only IE4+ supports .innerHTML. Actually, NS6 does too. And for NS4, you would use the LAYER tag, such as:

Code: Select all

<script>
function changeit()&#123;
document.test.document.write("<big>How are you doing?</big>")
document.test.document.close()
&#125;
</script>

<LAYER id="test" width=200px height=20px><big>My name is Bob</big></LAYER>

<br><br><form>
<input type="button" onClick="changeit()" value="Click here">
</form>
I've written a tutorial a while back on dynamically changing text/content in IE4/NS4/NS6 here: http://www.javascriptkit.com/javatutors ... tent.shtml

Posted: Mon Jul 15, 2002 2:47 pm
by MattF
The funniest thing I have ever seen in JS is this:

document.write("<noscript>You need to get a JavaScript compatible browser");

ROFL!

Posted: Wed Jul 17, 2002 7:16 am
by volka
h3h3, I like those scripts :D

http://www.pxl8.com/innerHTML.html shows how to use DOMHtml to perform things like innerHTML/Text. Will probaby use it from now on since I like it's capabilities. Unfortunally there are still some annoying bugs or incomplete implementations in the browser-enginges (seems that mozilla/netscape can score at this point)

Posted: Fri Jul 26, 2002 4:49 am
by gnu2php
I've learned that Netscape (since 6.0) has changed it's way of doing DHTML. See http://developer.apple.com/internet/jav ... dhtml.html

So, my example above won't work with it.

Good Reference on DHTML related issues

Posted: Tue Jan 14, 2003 7:13 pm
by Westmo
Everyone,

I recommend taking a look at Danny Goodman's book from O'Reilly press called "Dynamic HTML" ISBN 0-569-00316-1 for discussions on the DOM elements that are available for both Netscape & IE.

There are issues with using the <LAYER> tags - mostly because they are being phased out by the new HTML 4 standards, and will not work in 'strict' DTD's (although I have found that IE 6 sometimes still does it anyway!!).

I have been fighting a similar problem and run up against problems accessing the DOM (Document Object Model) that DHTML uses to perform dynamic updates from within PHP. If needed I can generate some code that will call JavaScript or VBScript event handlers from within PHP generated pages, but what I REALLY want to know is how to simply access the DOM directly from within PHP, or perhaps more correctly, to call PHP Event Handlers from within HTML.

Please see my post:
viewtopic.php?t=5636

If anyone has any insight on this I would appreciate the pointers. Thanx.

-Westmo