JavaScript: A Beginner’s Guide, 4th Edition

JavaScript: A Beginner’s Guide, 4th EditionReviews
Author: John Pollock
Pub Date: 2013
ISBN: 978-0-07-180938-2
Pages: 528
Language: English
Format: PDF
Size: 13 Mb


Fully updated for the latest JavaScript standard and featuring a new chapter on HTML5 and jQuery
JavaScript: A Beginner’s Guide shows how to create dynamic Web pages complete with special effects using today’s leading Web development language. With the growth of HTML 5, JavaScript is expected to grow even more to script the canvas element, add drag and drop functionality, and more. This fast-paced tutorial provides step-by-step coverage of the fundamentals, including variables, functions, operators, event handlers, objects, arrays, strings, and forms. The book then moves to more advanced techniques, including debugging, accessibility, and security. This pedagogically rich, hands-on guide explains how JavaScript works with HTML 5 and covers the new features available in JavaScript.
– 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
event handlers, and they offer the ability to attach multiple events to elements, whereas the DOM 0 method only allows one event to be registered on any given element. For example, suppose you had the following JavaScript code:

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?

A: Yes, but using client-side validation can help you save strain on your server, since those who have JavaScript enabled won’t need to access the server-side application each time invalid information is entered. It can also be helpful to the users, who will not need to reload the entire page to correct any invalid information.

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).

Q: I don’t use server-side scripts, but I use JavaScript for fun and want to validate the information. Do I really need to add a server-side script?

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.