CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   What are some alternatives to document.write()? (http://www.codingforums.com/showthread.php?t=259716)

Taro 05-03-2012 12:16 AM

What are some alternatives to document.write()?
 
Hello again,

I've continued to study and work on JavaScript. I've had some problems with the document.write() function. When I try to do a math problem, the whole content of the page clears out and only displays the solution. For example:
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function jahava()
  {
        var h = 1
var r = 4
var t = 5
document.write(h += r += t)
        }
       
</script>
</head>
<body>
<button OnClick="jahava()">Click Me!</button>
</body>
</html>

So If I put other content, like the button I was displaying (which I wanted to stay visible), the function would make them all disappear. I would again appreciate any help towards this matter.

Sincerely,
Taro B.

PS; This is not a calculator related problem, just in-general.

VIPStephan 05-03-2012 12:21 AM

Please make use of the search utility of this forum. If you type in “alternative document.write” you get a whole list of almost exactly the same question you asked.

felgall 05-03-2012 03:08 AM

innerHTML is the easy replacement for document.write that beginners should use. It does have a few limitations though so as you gain experience with javaScript you should look into the many Document Object Model commands that can manipulate the entire page content.


All times are GMT +1. The time now is 10:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.