O'Reilly logo

HTML, XHTML, & CSS All-in-One For Dummies®, 2nd Edition by Andy Harris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Talking to the Page

In This Chapter

  • Introducing the Document Object Model

  • Responding to form events

  • Connecting a button to a function

  • Retrieving data from text fields

  • Changing text in text fields

  • Sending data to the page

  • Working with other text-related form elements

JavaScript is fun and all, but it lives in Web browsers for a reason: to let you change Web pages. The best thing about JavaScript is how it helps you control the page. You can use JavaScript to read useful information from the user and to change the page on the fly.

Tip

In the first few chapters of this minibook, I concentrate on JavaScript without worrying about the HTML. The HTML code in those programs was unimportant, so I didn't include it in the code listings. This chapter is about how to integrate code with HTML, so now I incorporate the HTML as well as the JavaScript segments. Sometimes I still print code in separate blocks, so (as always) try to look at the code in its natural habitat, through your browser.

Understanding the Document Object Model

JavaScript programs usually live in the context of a Web page. The contents of the page are available to the JavaScript programs through a mechanism called the Document Object Model (DOM).

The DOM is a special set of complex variables that encapsulates the entire contents of the Web page. You can use JavaScript to read from the DOM and determine the status of an element. You can also modify a DOM variable and change the page from within JavaScript code.

Navigating the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required