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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write(ln)

Status
Not open for further replies.

AndyApp

Programmer
Joined
Dec 20, 2001
Messages
259
Location
GB
How can I get a javascript function to write some lines of html when it's called without overwriting the entire page?

I want to give users the option to view different products so they click on the name and javascript writes to the screen what it is they want to see. As i'm typing this i'm thinking i'll have to us vbscript?

"Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway" - Jim Davis (Garfield)
 

If you use document.write after the page has finished loading, the current content will be cleared.

You'll have to define a SPAN or DIV on the page, give it an ID, and use getElementById... something like this:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	function writeContent()
	{
		document.getElementById('wibble').innerHTML = '<b>Hello World!</b>';
	}
//-->
</script>
</head>
<body onload="writeContent();">
<div id="wibble"></div>
</body>
</html>

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top