www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help, writing text with variables

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    Help, writing text with variables

    I have a variable that generates any number from 0 - 20. When i do document.write("variable") it just deletes everything on the page and shows the random number. How can i make the random number to show up without having the rest of the page deleted. Thanks for your help!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    Quote Originally Posted by Bobofet View Post
    I have a variable that generates any number from 0 - 20. When i do document.write("variable") it just deletes everything on the page and shows the random number. How can i make the random number to show up without having the rest of the page deleted. Thanks for your help!
    Don't use document.write() It caused the page to reload if used after the page has been rendered.

    Create an element, for example:
    <div id="msg"></div>

    and then write to the element with
    document.getElementById('msg').innerHTML = "Your random number: '+Math.floor(Math.random()*20);

    Note: Code is untested since you did not provide anything to test against.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles