CONTENTS
List of Illustrations
Guide
Pages
INTRODUCTION
JAVASCRIPT IS A SCRIPTING LANGUAGE that enables you to enhance static web applications by providing dynamic, personalized, and interactive content. This improves the experience of visitors to your site and makes it more likely that they will visit again. You must have seen the flashy drop-down menus, moving text, and changing content that are now widespread on websitesthey are enabled through JavaScript. Supported by all the major browsers, JavaScript is the language of choice on the web. It can even be used outside web applicationsto automate administrative tasks, for example.
This book aims to teach you all you need to know to start experimenting with JavaScript: what it is, how it works, and what you can do with it. Starting from the basic syntax, youll move on to learn how to create powerful web applications. Dont worry if youve never programmed beforethis book will teach you all you need to know, step by step. Youll find that JavaScript can be a great introduction to the world of programming: with the knowledge and understanding that youll gain from this book, youll be able to move on to learn newer and more advanced technologies in the world of computing.
WHO THIS BOOK IS FOR
To get the most out of this book, youll need to have an understanding of HTML, CSS, and how to create a static web page. You dont need to have any programming experience.
This book will also suit you if you have some programming experience already and would like to turn your hand to web programming. You will know a fair amount about computing concepts, but maybe not as much about web technologies.
Alternatively, you may have a design background and know relatively little about the web and computing concepts. For you, JavaScript will be a cheap and relatively easy introduction to the world of programming and web application development.
Whoever you are, I hope that this book lives up to your expectations.
WHAT THIS BOOK COVERS
Youll begin by looking at exactly what JavaScript is, and taking your first steps with the underlying language and syntax. Youll learn all the fundamental programming concepts, including data and data types, and structuring your code to make decisions in your programs or to loop over the same piece of code many times.
Once youre comfortable with the basics, youll move on to one of the key ideas in JavaScriptthe object. Youll learn how to take advantage of the objects that are native to the JavaScript language, such as functions, dates, and strings, and find out how these objects enable you to manage complex data and simplify your programs. Next, youll see how you can use JavaScript to manipulate and detect objects made available to you in the browser and detect the browsers.
From here, youll move on to more advanced topics, such as writing code to dynamically manipulate elements within a web page and executing code when certain things happen within your page. Youll also learn how to script forms and other controls. Using this knowledge, you can start to create truly professional-looking applications that enable you to interact with the user.
Youll then learn how to store data within the browser and communicate directly with a server. Youll also learn how to write code for the new HTML5 media elements, and write your own custom user interface for them.
Youll explore some of the time saving JavaScript frameworks such as jQuery, Modernizr, Prototype, and MooTools and see how they work and how they can help you create sophisticated JavaScript powered applications.
Finally, youll look at common syntax and logical errors, how you can spot them, and how to use the JavaScript debuggers for Chrome, Internet Explorer, Firefox, Safari, and Opera to aid you with this task. Also, you need to examine how to handle the errors that slip through the net, and ensure that these do not detract from the experience of the end user of your application.
All the new concepts introduced in this book will be illustrated with practical examples, which enable you to experiment with JavaScript and build on the theory that you have just learned.
Youll find four appendixes at the end of the book. Appendix A provides solutions to the exercises included at the end of most chapters throughout the book. The remaining appendixes contain the reference material that your authors hope you find useful and informational. Appendix B contains the JavaScript languages core reference. Appendix C contains a complete W3C DOM Core referenceas well as information on the HTML DOM and DOM level 2 Event model. Appendix D contains the decimal and hexadecimal character codes for the Latin-1 character set.
WHAT YOU NEED TO USE THIS BOOK
Because JavaScript is a text-based technology, all you really need to create documents containing JavaScript is a text editor. Any will do.
Also, in order to try out the code in this book, you will need a web browser that supports a modern version of JavaScript. Ideally, this means the latest versions of Chrome, Internet Explorer, Firefox, Safari, and Opera. The book has been extensively tested with these browsers. However, the code should work in any modern web browser. Where there are exceptions, they will be clearly noted.
CONVENTIONS
To help you get the most from the text and keep track of whats happening, weve used a number of conventions throughout the book.
TRY IT OUT
The Try It Out is an exercise you should work through, following the text in the book.
- It usually consists of a set of steps.
- Each step has a number.
- Follow the steps with your copy of the database.
As you work through each Try It Out, the code youve typed will be explained in detail.
WARNING Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.
NOTE Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
As for styles in the text:
- We highlight in italic type new terms and important words when we introduce them.
- We show keyboard strokes like this: Ctrl+A.
We show file names, URLs, and code within the text like so:
persistence.properties
.
We present code in two different ways:
Important code in code examples is highlighted with a gray background
.
The gray highlighting is not used for code thats less important in the present context, or that has been shown before.
SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code manually or to use the source-code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com
. Once at the site, simply locate the books title (either by using the Search box or by using one of the title lists) and click the Download Code link on the books detail page to obtain all the source code for the book.
NOTE Because many books have similar titles, you may find it easiest to search by ISBN; this books ISBN is 978-1-118-90333-9.
Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx
to see the code available for this book and all other Wrox books.
You can also view the examples presented in this book at