Download Sams teach yourself JavaScript in 21 days PDF

TitleSams teach yourself JavaScript in 21 days
Author
LanguageEnglish
File Size5.4 MB
Total Pages778
Table of Contents
                            Sams Teach Yourself JavaScript™ in 21Days
	Copyright © 2002 by Sams Publishing
	Contents at a Glance
	Contents
	About the Authors
	Tell Us What You Think!
Introduction
	How This Book Is Organized
	Who Should Read This Book
	What This Book Assumes
	Conventions Used in This Book
	What’s on the Web Site?
WEEK 1 A Sound Foundation
	DAY 1 Getting the Basics Right
		Introducing JavaScript
		JavaScript in Context
		Selecting the Right Technology
		JavaScript, Jscript, and ECMAScript
		Let’s Get Started
		Data Types
		Some Useful Tools
		Summary
		Workshop
	DAY 2 Working with Data
		Simple Data Storage
		Operators
		JavaScript Operators
		Summary
		Workshop
	DAY 3 Functions and Statements
		User Defined Functions
		Predefined Global Functions
		What Is a Statement?
		Control Statements
		Loop Statements
		Summary
		Workshop
	DAY 4 JavaScript Is Object-Based
		Understanding Objects
		Client-Side JavaScript Objects
		The document Object
		Environment Objects
		Core JavaScript Objects
		Exploring an Object
		Summary
		Workshop
	DAY 5 An Introduction to Arrays
		What Is an Array?
		Creating an Array
		Accessing Arrays
		Array Properties
		Array Methods
		Associative Arrays
		Storing Objects in Array Elements
		Summary
		Workshop
	DAY 6 HTML Forms and the String Object
		Collecting Data from HTML Forms
		Form Elements
		The String Object
		Checking User Input
		Summary
		Workshop
	DAY 7 Numbers and Math
		The Number Object
		The Math Object
		Predefined Properties
		Methods of the Math Object
		Creating Your Own Math Functions
		Summary
		Workshop
WEEK 2 Let’s Take It Further
	DAY 8 The Browser Issue
		Different Browsers, Different JavaScript
		Cross-Browser Compatible Scripting
		The W3C DOM
		Summary
		Workshop
	DAY 9 Date and Time Manipulation
		JavaScript and Dates
		The Date Object
		Date Formatting
		Time Formatting
		Converting Date and Time Formats
		Summary
		Workshop
	DAY 10 Events and Event Handling
		Understanding Events
		Types of Events
		How to Handle Events
		Summary
		Workshop
	DAY 11 Dynamic HTML
		What is DHTML?
		Using Cascading Style Sheets
		Working with Layers
		Changing Attributes of an HTML Element
		Moving Things
		Summary
		Workshop
	DAY 12 Windows and Frames
		What Are Windows and Frames?
		Determining Window Location
		Working with Window History
		Working with the Status Line
		Using the Screen Object
		Working with Frames
		Working with Popups
		Summary
		Workshop
	DAY 13 Regular Expressions Make It Easier
		Why Regular Expressions Are Useful
		What Is a Regular Expression?
		Some Simple Patterns
		Regular Expressions Overview
		Defining Regular Expressions
		Quantifiers
		The Methods of the RegExp Object
		The Properties of the RegExp Object
		Summary
		Workshop
	DAY 14 Advanced Array Management
		The Array Object’s Methods
		Multidimensional Arrays
		Summary
		Workshop
WEEK 3 Advanced Topics
	DAY 15 Debugging and Error Handling
		Preventing and Classifying JavaScript Errors
		Finding Syntax Errors
		Debugging Load-Time Errors
		Debugging Run-Time Errors I: Discrete Events
		Debugging Run-Time Errors II: Continuous Events
		Advanced Debugging Techniques
		Using JavaScript Debuggers
		Summary
		Workshop
	DAY 16 Cookies: Storing Persistent Data
		Maintaining State
		Cookies: An Introduction
		Using Cookies
		Other State Maintenance Options
		Summary
		Workshop
	DAY 17 Privacy and Security
		Privacy for Web Users
		Privacy for Webmasters
		Privacy Impact on JavaScript
		Summary
		Workshop
	DAY 18 Plugins and Applets
		Plugins Versus Applets
		Detecting Plugin Installation
		Working with Plugin Objects
		Working with Applets
		Summary
		Workshop
	DAY 19 Creating Your Own Objects
		What Is a Custom Object?
		Use of the Constructor to Create Objects
		Creating an Instance of a Custom Object
		Creating Object Methods
		Linking Objects Together
		Summary
		Workshop
	DAY 20 JavaScript in E-Commerce
		Requirements for an E-Commerce Site
		Shop Structure
		The Online Catalog
		Shopping Carts
		Summary
		Workshop
	DAY 21 JavaScript and SVG
		Overview of Scalable Vector Graphics
		Example SVG Code
		The SVG Document Object Model
		Using JavaScript in SVG
		JavaScript Beyond Declarative Animation
		Interaction Between the HTML and SVG DOM
		Finding Out More About SVG
		Summary
		Workshop
Appendixes
	APPENDIX A New Features in JavaScript 1.5
		Number Formatting Additions
		Runtime Error Messages
		Regular Expressions
		Conditional Function Declarations
		Functions Can Be Declared Within an Expression
		Multiple Catch Clauses
	APPENDIX B Color Codes
		Color Names Specified as Plain-Language
		Hexadecimal Color Value
		RGB Color Values
	APPENDIX C Functions Reference
		abs()
		acos()
		asin()
		atan()
		atan2()
		atob()
		Boolean()
		btoa()
		captureEvents()
		catch()
		ceil()
		cos()
		Date()
		decodeURI()
		decodeURIComponent()
		encodeURI()
		encodeURIComponent()
		Error()
		escape()
		eval()
		exp()
		floor()
		Function()
		GetObject()
		handleEvent()
		isFinite()
		isNaN()
		log()
		max()
		min()
		Number()
		Object()
		parseFloat()
		parseInt()
		pow()
		random()
		releaseEvents()
		rgb()
		round()
		routeEvents()
		ScriptEngine()
		sin()
		sqrt()
		tan()
		toString()
		unescape()
		unwatch()
		watch()
	APPENDIX D Resources Online
		JavaScript
		Java and Java Applets
		HTML
		CGI
	APPENDIX E A Short History of JavaScript
		Evolution of the Internet
		Internet Programming Revolution
		JavaScript Introduction
		Browser Support of JavaScript Versions
INDEX
                        
Document Text Contents
Page 2

800 East 96th St., Indianapolis, Indiana, 46240 USA

Andrew Watt and Jonathan Watt
with Jinjer Simon and Jim O’Donnell

JavaScript


in 21 Days

Teach Yourself

00 2978 FM 4/10/02 10:45 AM Page i

Page 389

Specify the Classification Properties
You can use the classification properties to control the appearance of an HTML element,
its location in respect to another HTML element, and the visibility of the HTML ele-
ment. Table 11.5 outlines these properties for setting the classification of an element.

TABLE 11.5 CSS Classification Properties
Property Values

clear Indicates sides where floating elements are not allowed: left, right, both,
or none

cursor URL of cursor to display, or one of the following: auto, crosshair,
default, pointer, move, e-resize, ne-resize, nw-resize, n-resize,
se-resize, s-resize, w-resize, text, wait, help, or hand

display Value indicating how element displays: none, inline, block, list-item,
run-in, compact, marker, table, inline-table, table-row-group, table-
header-group, table-footer-group, table-row, table-column-group,
table-cell, or table-caption

float Where an image or text appears on the element: left, right, none

visibility Visibility value: visible, hidden, collapse

Specifying the Dimension Properties
You can use the dimension properties to control the width and height of a particular
image. You can also use these properties to specify the distance between lines of text. For
example, the following rule sets the height and width of an <img> tag:

img { height: 100px;
width: 100px }

Table 11.6 outlines the dimension properties you can use.

TABLE 11.6 CSS Dimension Properties
Property Values

height auto Browser uses actual image height. You can specify a numeric value in
px, cm, or another CSS unit. You can also specify a percentage of the block
containing the image.

line-height normal Browser sets the height. Use a number, such as 2, that is multiplied
by font size to set distance. Specify a CSS unit, such as 10px. You can also
specify a percentage of the current font size.

width auto Browser uses actual image width. You can specify a numeric value in
px, cm, or another CSS unit. You can also specify a percentage of the block
containing the image.

366 Day 11

14 2978 CH11 4/10/02 10:42 AM Page 366

Page 390

Dynamic HTML 367

11

Changing the Font Properties
Probably one of the most obvious reasons for having style sheets is to have the ability to
adjust the font properties for an HTML element. For example, you may want to make
sure that the text is always displayed in a particular font, or that the headings are bold
and underlined. Table 11.7 outlines the various font properties that you can set in the
Cascading Style Sheet.

Keep in mind, if a browser does not support a font you specify, the brows-
er’s default font is used. Therefore, try to use common fonts that most
people have on their systems to ensure your page displays as intended.

Caution

TABLE 11.7 CSS Font Properties
Property Values

font-family List of font names to use for the HTML element. By providing multiple
fonts, the browser has another font to use if the first font is not available.
Separate the list with commas.

font-size Specify a fixed size in pixels, such as 10px, or a percentage of the parent
element. Use smaller or larger to adjust the size based on the parent ele-
ment. You can also use: xx-small, x-small, small, medium, large, x-large,
and xx-large.

font-style normal Displays normal font. italic Displays an italic font. oblique
Displays an oblique font.

font-variant normal Displays normal font. small-caps Displays text with smallcaps.

font-weight normal Displays normal characters. bold Displays thick characters. bolder
Displays thicker characters. lighter Displays lighter characters. 100 – 900
Numeric value defining thin to thick. 400 equals normal and 700 equals
bold.

Setting List Properties
You can customize the way your lists display using the different list style properties
outlined in Table 11.8.

14 2978 CH11 4/10/02 10:42 AM Page 367

Page 777

dates, 308-309
combining, 316-317
converting, 314-315, 323-327
Date object, 309-312
formatting, 312-315

floating math point errors, 636-637
hexadecimal, 695-697
intermediate, 511-514
MAX VALUE/MIN VALUE, 257
objects, 611-613
radio buttons, 228-230
RGB colors, 698
select boxes, 230-233
strings, 326-327
text elements, 221-223
textarea elements, 223-225
time

converting, 319-326
formatting, 317-321
zones, 322-323

variable numbers of occurrences, patterns,
430-436

variables, 48
creating, 48-53
hidden form cookie variables, 561-562
modifying, 52
naming, 50-51
reassigning, 52
scope, 89-90
tracking, 497
windows, 385

verifying lugins, 588-592
versions

browsers, 292-296
JavaScript, 727
support, 289

viewers
Batik DOM, 656-658
SVG, 653

viewing
associative arrays, 194
MAX VALUE/MIN VALUE, 257
multiple documents, 384. See also Window

object

W

W3C (World Wide Web Consortium), 359
DOM, 298-302
JavaScript, 719

watch() function, 716
Web

browser window access, 569
cookies, 532-533, 568

advantages, 534
disadvantages, 534-535
FavList.htm example, 553
future of, 557
limitations, 534
myths, 535
Netscape specification Web site, 535

file restrictions, 566-567
resource limitations, 569
users, 566

Web pages
animation, 377-380
applets

calling, 597-598
interacting, 598-599

DHTML, 358
creating, 363-370
CSS, 358-363
layers, 371-374

plugins
detecting, 585-587
objects, 594-595
support, 592-594
verifying, 588-592

754 values

32 2978 Index 4/10/02 10:43 AM Page 754

Page 778

Web sites
Cookie Central, 557
e-commerce

coding shopping carts, 641-645
online shopping carts, 625-634
requirements, 622
shopping carts, 635-640, 645
structures, 622-624

frames, 407
HotWired, 558
HTTP Working Group (IETF), 557
Netscape

cookie spec page, 557
cookie specification, 535

Robert Brook’s Cookie Taste Test, 558
WebDraw, 652
Webmasters, 570-572
WebReference.com, 719
while statements, 111-112
white space, 22-23

configuring, 368
regular expressions, 443-444

Window object, 122-130, 383-384
windows, 385. See also interfaces

browsers, 569
chrome, 387-388
closing, 389-390
debug browser, 527
events, 346
frames, 399
histories, 393-394
methods, 385-390
navigating, 126
opening, 386-389
popups, 409-410
positioning, 390-393
properties, 385-390
Screen object, 397-399
status lines, 394-396
URLs, 391

Windows Media Player, 586
words

boundaries, 443-444
reserved, 34-35

World Wide Web Consortium. See W3C
writing HTML, 136
WWW (World Wide Web). See Web

X-Y-Z

ZDNet Developer, 720
zones, time, 322-323

zones 755

32 2978 Index 4/10/02 10:43 AM Page 755

Similer Documents