|
-
Oct 29th, 2005, 08:19 AM
#1
Thread Starter
Lively Member
[Resolved] JavaScript: document.write in a function
Does anyone know why document.write hangs my browser with the code below. Commenting document.write out solves the problem.
Thanks,
<html>
<head>
<title>Functions</title>
<script language="JavaScript"
type="text/javascript">
function addem(){ // function defined within <head> tags
var n = 2;
var y = 3;
//alert("hi");
document.write( n + y, "<br>");
}
</script>
</head>
<body bgcolor=red>
<a href="javascript:addem()">Click here</a>
<h2>Hello</h2>
</body>
</html>
Last edited by whiteWay; Oct 29th, 2005 at 05:15 PM.
-
Oct 29th, 2005, 09:46 AM
#2
Re: JavaScript: document.write in a function
You can only call document.write while the page is loading. If you want to dynamically replace text you should create a div element with an ID and use document.getElementById() to access it and replace its content.
-
Oct 29th, 2005, 05:14 PM
#3
Thread Starter
Lively Member
Re: JavaScript: document.write in a function
Thanks,
I forgot that document.write can only be used when the page is loading. Using the div element helps to dynamically fill the info I want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|