This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with displaying data properly

 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take it easy on me, complete JavaScript newb

Here is my simple code (CSS added into head for readability):



The user enters a number in a box and presses "Count" and the number is printed on the screen starting with 1, 2, 3, ... up to the users number. My question is that when this runs it does it on a fresh white screen with everything else gone. How do I go about having the output "1, 2, 3, etc" as part of the page itself. How can I not only add it into the page but put it into it's own div or class so that I can control how the output will look?

Thank you in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64856
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.write() should be avoided like the plague. It's only useful during the initial run of displaying the page, and even then there are better ways to do things. Used after the page is initially displayed, it replaces the page with whatever you are writing, as you have seen. Pretend it does not exist.

Rather, investigate DOM manipulation and the use of the innerHTML property.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see...

Well, always good to know you've learned a bunch of useless commands

Thanks again Bear!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64856
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Learning what to avoid is as important as learning what to do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic