It's often useful to generate web pages (dynamic documents) from
Create dynamic documents with document.write().
This method can:
Here's a sample page
that simply displays today's date.
Here's the source code.
Compare the original source code to what you see when you View Source
in the browser itself.
- insert text into the current web page (as seen earlier)
- create an entirely new document (what this chapter is about)
- Create a web page containing a form containing a button.
- When the button is clicked, generate a dynamic web page.
- Hint: onClick invoke document.write().
Don't peek unless you're stuck!
Extra for Experts
- Instead of replacing the web page in the existing
browser window, open a new window and load the dynamic
page into it. Hint: use the Window.open() method.
- Here's a "cleaner" version
(and its source code) of the
example program shown at the beginning of this chapter...
but it's got a bug. Explain.