JavaScript; document.write()

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

JavaScript; document.write()

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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>
georgec
Forum Newbie
Posts: 1
Joined: Sun Jul 14, 2002 6:13 pm

Post 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
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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.
Westmo
Forum Newbie
Posts: 3
Joined: Tue Jan 14, 2003 6:49 pm

Good Reference on DHTML related issues

Post 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
Post Reply