Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post

    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.
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,777
    Thanks
    6
    Thanked 1,021 Times in 994 Posts
    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.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •