Chapter 18. Controls: getting user input
This chapter covers
- Using buttons to initiate actions
- Collecting user input with text boxes and drop-down lists
- Calling functions automatically when a button is clicked
We love buttons! Whether we’re buying books on Amazon, liking a tweet, or sending that late-night drunken email, we find it hard to resist clicking those alluring, colorful buttons. Well, it’s time for you to issue your own calls to action and start adding buttons to your pages. And while you’re at it, you need to make space for text boxes and drop-down lists too.
In chapter 17 you made the jump to HTML and used JavaScript to add content to a web page. To get user input, however, you stuck with the console. In these days of flashy web apps you want the users to interact solely via the web page; they shouldn’t have to know JavaScript and go searching for the console to use the programs you write for them.
This chapter introduces the HTML input, select, and button elements, letting users type information and commands into a text box, choose from a drop-down list, and initiate actions by clicking buttons. You see how to set up functions that are automatically called when a button is clicked.
It’s fun to click buttons, so let’s start with those. Click!