Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris
ARITHMETIC OPERATORS OperatorDescriptionExampleValue of Quantity =assignquantity = additionquantity = subtractionquantity = *multiplicationquantity = 10 * 220 /divisionquantity = 10 / 25 2
COMPARISON OPERATORS OperatorDescriptionExampleSample values of quantity that would result in true = =Double equals sign (equivalent) “is exactly equal to” quantity = = 1010 >Greater thanquantity > 1011, 12 (but not 10) > =Greater than or equal to quantity > = 1010, 11, 12 <Less thanquantity < 108, 9 (but not 10) < =Less than or equal to quantity < = 108, 9, 10 ! =Not equal toquantity ! = 108, 9, 11 (but not 10) 3
Copyright © Terry Felke-Morris DECISION MAKING if (condition) { … commands to execute if condition is true } else { … commands to execute if condition is false } 4
Copyright © Terry Felke-Morris HANDS-ON PRACTICE 14.6 Page 561 chapter14/quantityif.html 5
Copyright © Terry Felke-Morris FUNCTION A function is a block of one or more JavaScript statements with a specific purpose, which can be run when needed. function function_name() {... JavaScript statements … } 6
Copyright © Terry Felke-Morris USING FUNCTIONS function showAlert() { alert("Please click OK to continue."); } 7 Calling the Function showAlert(); Defining the Function
Copyright © Terry Felke-Morris HANDS-ON PRACTICE 14.7 Page 564 chapter14/quantityif2.html 8
Copyright © Terry Felke-Morris VALIDATING FORM FIELDS Use the "" or null to check to determine if a form field has information if (document.forms[0].userName.value == "" ) { alert("Name field cannot be empty."); return false; } // end if 9
Copyright © Terry Felke-Morris FORM VALIDATION It is common to use JavaScript to validate form information before submitting it to the web server. Is the name entered? Is the address of correct format? Is the phone number in the correct format? See Hands-on Practice
Copyright © Terry Felke-Morris HANDS-ON PRACTICE 14.8 Page 567 chapter14/formvalidation.html 11
Copyright © Terry Felke-Morris JAVASCRIPT & ACCESSIBILITY Don’t expect JavaScript to always function for every visitor Some may have JavaScript disabled Some may be physically unable to click a mouse Provide a way for your site to be used if JavaScript is not functioning Plain text links contact info 12