Author: John Pollock
Pub Date: 2013
Size: 13 Mb
– Key Skills & Concepts–Chapter-opening lists of specific skills covered in the chapter
– Ask the Expert–Q & A sections filled with bonus information and helpful tips
– Try This–Hands-on exercises that show you how to apply your skills
– Notes–Extra information related to the topic being covered
– Tips–Helpful reminders or alternate ways of doing things
– Self-Tests–End-of-chapter reviews to test your knowledge
– Annotated syntax–Example code with commentary that describes the programming techniques being illustrated
– Code downloads provided for projects in the book
Ask the Expert
Q: Why are there so many events?
A: There are so many things that a viewer (or the browser itself) can do while on a Web page that you end up with a bunch of possible events.
Q: Do I need to memorize all of these events?
A: You probably only need to memorize them if you are taking a test, or you are doing this for a job and need to know things quickly, or if you just like knowing the events off the top of your head; otherwise, you can just refer to Table 10-1 in this chapter if you are not sure which event needs to be used.
Q: Will I be using every single event in this book while doing the projects in this book?
A: Since this book is a beginner’s guide, you will not get to the point where you use every single event.
Other Ways to Register Events
Up to this point, you have been using what are called DOM Level 0 event handlers (onclick, onmouseover, and so on). There are two other methods for registering events in addition to the method you have used: addEventListener() and attachEvent(). These are called DOM Level 2
The Event Object
When an event occurs, an object named eventis created, which stores information about the event. This information can be used by your script to help it perform the required actions. For example, a keyboard event will have information about the key that was pressed stored in the event object. This allows you to program different responses when different keys are pressed. The event object works a little differently in Internet Explorer (prior to version 9), so you will first take a look at how to use the event object with all browsers that support it.
Ask the Expert
Q: Is validation necessary? After all, couldn’t it be handled by the server-side application?
Q: What types of input can I validate?
A: For the most part, you can validate anything you like in the manner you see fit. You can validate dates, names, times, addresses, e-mail addresses, phone numbers, or anything else you might need.
Q: Can I validate the selections in a select box or the text in a text area, or maybe some of the other input types?
A: In some of these cases, you will already have your own values built into the elements. However, if you can, you should still validate those values against other information to be sure the information you receive matches your needs. You just need to adjust your function to perform the needed tasks based on the different types of input devices (text areas, radio buttons, and so on).
A: The need for a server-side script depends on your purposes. If you have a form that needs to have information saved, sent by e-mail, or sent to a database, then you need a server-side application.