
02_574973 ftoc.qxd 9/9/04 10:42 AM Page vi TABLE OF CONTENTS HOW TO USE THIS BOOK . .xii 1 INTRODUCING JAVASCRIPT . .2 Introduction to JavaScript ....................................................................................2 Enter a JavaScript Statement into the Address Bar ..............................................4 Embed JavaScript in an HTML Document ............................................................6 Link an External JavaScript File ............................................................................8 Present Content to Non-JavaScript Enabled Browsers ........................................10 Add a Comment to JavaScript Code ....................................................................12 Protect the Source Code ......................................................................................14 2 USING VARIABLES AND ARRAYS . .16 Understand Variable Types ................................................................................16 Declare Variables ................................................................................................18 Assign Values to Variables ................................................................................19 Display Integers ..................................................................................................20 Display Floating-Point Numbers ........................................................................21 Display Booleans ................................................................................................22 Display Strings ..................................................................................................23 Determine Variable Type ....................................................................................24 Convert Strings to Numbers ................................................................................26 Convert Numbers to Strings ................................................................................27 Declare an Array ................................................................................................28 Declare a Multidimensional Array ......................................................................30 Determine the Number of Elements of an Array ................................................32 Convert an Array into a String ..........................................................................34 Sort an Array ......................................................................................................36 Remove Elements from an Array ........................................................................38 Add Elements to anCOPYRIGHTED Array ..................................................................................39 MATERIAL 3 CREATING EXPRESSIONS . .40 Using the Arithmetic Operator ............................................................................40 Increment and Decrement Values ........................................................................42 Create Comparison Expressions ..........................................................................44 Create Logical Expressions ................................................................................46 vi 02_574973 ftoc.qxd 9/9/04 10:42 AM Page vii Identify Numbers ................................................................................................48 Evaluate an Expression ......................................................................................50 Inform the User with an Alert Dialog Box ..........................................................51 Enable User Input with a Prompt Dialog Box ....................................................52 Enable User Decisions with a Confirm Dialog Box ..............................................54 4 HANDLING EVENTS . .56 JavaScript Events ................................................................................................56 Detect a Mouse Click ..........................................................................................58 Create Rollover Buttons ......................................................................................60 Detect a Key Press ..............................................................................................62 Detect a Modifier Key Combination ....................................................................64 Set and Remove Focus ........................................................................................66 Onchange Event ................................................................................................68 Handle the Page Load and Onunload Operations ................................................70 Execute a JavaScript Statement from an HTML Link ........................................72 Attach an Event to an Object ..............................................................................73 Determine the Element That Received the Event ................................................74 Determine Which Mouse Button Was Pressed ....................................................76 Cancel Browser Events ......................................................................................77 5 CONTROLLING PROGRAM FLOW . .78 Limit Executions with If-Else Statements ..........................................................78 Using Conditional Operators ..............................................................................80 Optimize Performance with a Switch Statement ..................................................81 Create a For Loop ..............................................................................................82 Continue and Break Loops ..................................................................................83 Handle While Loops ..........................................................................................84 Create a Timed Interval ......................................................................................86 Set a Regularly Timed Interval ............................................................................88 Declare and Call a Function ................................................................................90 Handle Global and Local Variables ....................................................................91 Pass Parameters to a Function ............................................................................92 Return a Value from a Function ..........................................................................93 Increase Script Performance ................................................................................94 vii 02_574973 ftoc.qxd 9/9/04 10:42 AM Page viii TABLE OF CONTENTS 6 UTILIZING STRINGS . .96 Determine the Length of a String ........................................................................96 Select Portions of a String ..................................................................................98 Change the Case of a String ..............................................................................100 Extract Characters from a String ......................................................................102 Escape a Text String ........................................................................................104 Encode a URI ....................................................................................................105 Regular Expression ..........................................................................................106 Match the Character in a String ........................................................................108 Replace Characters in a String ..........................................................................110 7 WORKING WITH HTML FORMS . .112 Develop HTML Forms ......................................................................................112 Reference Form Elements ................................................................................113 Validate a Text Box Value ................................................................................114 Validate a Password Field ................................................................................116 Work with a Hidden Element ............................................................................118 Validate Text Area Input ..................................................................................120 Work with a Button Element ............................................................................121 Apply Reset and Submit Buttons ......................................................................122 Alter Check Box Properties ..............................................................................124 Determine Selected Radio Button ......................................................................126 Work with a Selection List ................................................................................128 Basic Form Validation ......................................................................................130 Create a Select Element Navigation Menu ........................................................132 Block an Enter Key Invoked Form Submission ................................................134 Advance the Text Field Focus with the Enter Key ............................................136 8 WORKING WITH DATES AND TIMES . .138 Use the Date Object to Display Dates ................................................................138 Get the Date and Time Components ..................................................................140
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-