02.06.2013 Views

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Going Further with<br />

Java Script<br />

This chapter covers various concepts that can help make you a better <strong>JavaScript</strong><br />

programmer. You don’t need most of the ideas here to write functioning <strong>JavaScript</strong><br />

programs, so don’t worry if you don’t understand them all. <strong>The</strong> first<br />

few sections provide helpful tips and methods for working with strings, numbers,<br />

and dates, and once you’ve mastered the basics, these sections can really help you<br />

process visitor input in forms, work with HTML and HTML attributes, and generate<br />

dates for calendars. <strong>The</strong> section “Putting It All Together” on page 457 contains some<br />

good advice for beginners, but you can program happily for a long time without<br />

needing the information in the other sections in this chapter. But if you want to<br />

expand your skills, this chapter can point you in the right direction.<br />

Working with Strings<br />

Strings are the most common type of data you’ll work with: input from form fields,<br />

the path to an image, a URL, and HTML that you wish to replace on a page are all<br />

examples of the letters, symbols, and numbers that make up strings. You learned the<br />

basics of strings in Chapter 2, but <strong>JavaScript</strong> provides a lot of useful methods for<br />

working with and manipulating strings.<br />

Determining the Length of a String<br />

<strong>The</strong>re are times when you want to know how many characters are in a string. For<br />

example, say you want to make sure that when someone creates an account on your<br />

top secret website, they create a new password that’s more than 6 letters but no more<br />

than 15. Strings have a length property that gives you just this kind of information.<br />

www.it-ebooks.info<br />

chapter<br />

14<br />

425

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!