1 Week 8 Final Project Planning & Chapter 6 JavaScript Advanced Web Development IT225 Spring Term 2016 Marymount University School of Business Administration.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Server-Side vs. Client-Side Scripting Languages
Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
Capturing user input: Using HTML FORMs CS4320 got here on 27/11/2003.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
XHTML Forms for Data Collection and Submission Chapter 5.
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
PHP: Hypertext Processor Fred Durao
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
JavaScript Form Validation
Server- Side technologies Client-side vs. Server-side scripts PHP basic ASP.NET basic ColdFusion.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 9 Scott Marino.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Project Four Forms Discuss form processing Describe the difference between client-side and server-side form processing Add a horizontal rule to a Web page.
JavaScript for Client-Side Computation and Data Validation Chapter 06.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
WLLS 102 Class 12 4/30/2004 Professor C. Shilepsky Wells College.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
Logical Operators.  Quiz  Let's look at the schedule  Logical Operators 2.
Project 3: Understanding the JavaScript Object Model Essentials for Design JavaScript Level One Michael Brooks.
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
IST 210: PHP Basics IST 210: Organization of Data IST2101.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
1 Week 11 PHP for Server-Side Preprocessing (Chapter 8) Advanced Web Development IT225 Spring Term 2016 Marymount University School of Business Administration.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Advanced Web Development IT225
Build in Objects In JavaScript, almost "everything" is an object.
Tutorial 10 Programming with JavaScript
Advanced Web Development IT225
JavaScript is a programming language designed for Web pages.
JavaScript for Client-Side Computation and Data Validation
Web Programming– UFCFB Lecture 17
More Selections BIS1523 – Lecture 9.
Programming in JavaScript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Presentation transcript:

1 Week 8 Final Project Planning & Chapter 6 JavaScript Advanced Web Development IT225 Spring Term 2016 Marymount University School of Business Administration Professor Suydam

2 Chapter 6 JavaScript for Client-Side Computation and Data Validation JavaScript Tags Functions Calculations Outputs Math Objects.js BMI Calculator page Feedback page MP4 Starter Site MP3 Requirements Review

3 Understand JavaScript mathematical operators Understand Boolean Logic for programming Importance of keeping web page content behavior separate from content structure and content presentation, both conceptually and physically Overview of JavaScript as a programming language Write to a web page for user notification using JavaScript External and embedded JavaScript code The Document Object Model (DOM) and JavaScript access to it JavaScript data types and variables, functions, expressions, control statements, arrays, and built-in objects Importance of website security and how JavaScript can help to achieve it Regular expressions and their use in JavaScript Update our BMI calculator and our feedback forms to incorporate validation of user input

4 Source:

Assume that a =1, b =2, and c =2. What is the value of each of the following Boolean expressions? a)(a>1) OR (b=c) b) [(a+b)>c] AND (b<=c) c) NOT (a=1) d) NOT [(a=b) OR (b=c)] a)True b) True c)False d)False 5

6 && = Logical AND ||=Logical OR !=Logical NOT

7

8 Copy/Paste bmi and form pages created for mp2 into mp4 folder Add following script tags into the bmi page within the tags

9 function processBMIform() { var bmiFormObj = document.getElementById("bmiForm"); if (validateInput(bmiFormObj)) { var bmi = calculateBMI(bmiFormObj); if (bmiFormObj.details.checked) displayDetailed(bmiFormObj, bmi); else alert("Your BMI: " + precision(bmi)); } Copy/paste the following function into a script page name bmi.js and save in the js folder

10 function validateInput(bmiFormObj) { var hUnit = bmiFormObj.heightUnit.options[bmiFormObj.heightUnit.selectedIndex].text; var wUnit = bmiFormObj.weightUnit.options[bmiFormObj.weightUnit.selectedIndex].text; var height = bmiFormObj.height.value; var weight = bmiFormObj.weight.value; var = bmiFormObj. .value; var heightOK, weightOK, OK; if (hUnit == "inches") heightOK = validateInches(height); else heightOK = validateCentimetres(height); if (wUnit == "pounds") weightOK = validatePounds(weight); else weightOK = validateKilograms(weight); if (bmiFormObj.wantMail.checked) { OK = validate ( ); alert("Warning: The feature is currently not supported.") } else OK = true; return heightOK && weightOK && OK; } Add following validation function after the previously pasted functions

11 function validateInches(height) { if (isNaN(height)) { alert("Error: Please input a number for height.") return false; } if (height 100) { alert("Error: Height must be in the range inches.") return false; } return true; } Height function validateCentimetres(height) { if (isNaN(height)) { alert("Error: Please input a number for height.") return false; } if (height 300) { alert("Error: Height must be in the range centimeters.") return false; } return true; } Weight function validatePounds(weight) { if (isNaN(weight)) { alert("Error: Please input a number for weight.") return false; } if (weight 1000) { alert("Error: Weight must be in the range pounds.") return false; } return true; } function validateKilograms(weight) { if (isNaN(weight)) { alert("Error: Please input a number for weight.") return false; } if (weight 500) { alert("Error: Weight must be in the range kilograms.") return false; } return true; } Add following validation functions after the previously pasted functions

12 function validate (address) { var p = if (p == 0) return true; else { alert("Error: Invalid address."); return false; } Note: Regular expressions will be examined in more detail later. This one simply says, “Look for at least one character followed followed by at least one more character.” So … not a very “robust” check for a valid ! Add following validation function after the previously pasted functions

13 function calculateBMI(bmiFormObj) { var hUnit = bmiFormObj.heightUnit.options[bmiFormObj.heightUnit.selectedIndex].text; var wUnit = bmiFormObj.weightUnit.options[bmiFormObj.weightUnit.selectedIndex].text; var height = bmiFormObj.height.value; var weight = bmiFormObj.weight.value; if (hUnit == "inches") height = inchesToCentimetres(height); if (wUnit == "pounds") weight = poundsToKilograms(weight); height /= 100; //Convert height from centimeters to meters var bmi = weight/(height*height); //kilograms/(meters*meters) return bmi; } function inchesToCentimetres(height) { var CENTIMETRES_PER_INCH = 2.54; return height * CENTIMETRES_PER_INCH; } function poundsToKilograms(weight) { var POUNDS_PER_KILOGRAM = 2.2; return weight / POUNDS_PER_KILOGRAM; } Add following calculation functions after the previously pasted validation functions

14 function displayDetailed(bmiFormObj, bmi) { var hUnit = bmiFormObj.heightUnit.options[bmiFormObj.heightUnit.selectedIndex].text; var wUnit = bmiFormObj.weightUnit.options[bmiFormObj.weightUnit.selectedIndex].text; var height = bmiFormObj.height.value; var weight = bmiFormObj.weight.value; var text = "BMI Report\n" + "Your weight: " + weight + " " + wUnit + "\n" + "Your height: " + height + " " + hUnit + "\n" + "Your BMI: " + precision(bmi) + "\n"; if (bmi < 18.5) text += "Your BMI suggests that you are underweight.\n"; else if (bmi < 25) text += "Your BMI suggests that you have a reasonable weight.\n"; else if (bmi < 29) text += "Your BMI suggests that you are overweight.\n"; else text += "Your BMI suggests that you may be obese.\n"; alert(text); } Add following display functions after the previously pasted functions

15 function precision(num) { var intPortion = Math.floor(num); var decimalPortion = Math.round(num*10)%10; var text = intPortion + "." + decimalPortion; return text; } Add following math precision function after the previously pasted functions

16 Constants Methods

17

18 function will be programming later in course. Usually data from a form is sent to the server for processing, but here we are dealing with client-side programming only, so we will not be sending our form data to a server in this chapter. All of our form data processing will be done on the client side using JavaScript. That is why the action attribute of the form tag still has an empty string as its value. (Scobey 186)

19 Add following script tags into the feedback page in mp4 folder within the tags Replace the original beginning form tag with:

20 function validateContactForm() { var contactFormObj = document.getElementById("contactForm"); var firstName = contactFormObj.firstName.value; var lastName = contactFormObj.lastName.value; var phone = contactFormObj.phone.value; var = contactFormObj. .value; var everythingOK = true; if (!validateName(firstName)) { alert("Error: Invalid first name."); everythingOK = false; } if (!validateName(lastName)) { alert("Error: Invalid last name."); everythingOK = false; } if (!validatePhone(phone)) { alert("Error: Invalid phone number."); everythingOK = false; } if (!validate ( )) { alert("Error: Invalid address."); everythingOK = false; } if (everythingOK) { alert("All the information looks good.\nThank you!"); return true; } else return false; } function validateName(name) { var p = name.search(/^[-'\w\s]+$/); if (p == 0) return true; else return false; } function validatePhone(phone) { var p1 = phone.search(/^\d{3}[-\s]{0,1}\d{3}[-\s]{0,1}\d{4}$/); var p2 = phone.search(/^\d{3}[-\s]{0,1}\d{4}$/); if (p1 == 0 || p2 == 0) return true; else return false; } function validate (address) { var p = if (p == 0) return true; else return false; }

21

22 function will be programmed later in course Since we are only dealing with client-side computing using JavaScript, we have not implemented the facility. All that happens is a message using the alert() method will be displayed to the user. Allowing JavaScript programs to send s from a client’s computer would be a major breach of security since malicious JavaScript code could exploit the ability to send spam from client computers. We will implement the facility when we study server-side computing using PHP. (Scobey )

23 Characters Denoting Positions in JavaScript Regular Expressions Characters that Can Be Used in JavaScript Regular Expressions

24 Character Classes that Can Be Used in JavaScript Regular Expressions Modifiers that Can Be Placed after a Pattern within a JavaScript Regular Expression to Indicate the Permissible Amount of Repetition of that Pattern

25 Once you have BMI Calculator and Feedback form working go back and read Chapter 6, then do Study Guide 3, to make sure you understand all the concepts.

26

27

28 Create and insert buttons as shown below (your choice on button styles and text) Link from frames pages to MP3 index.html

29 Create in Expression Web Minimum requirement – index.html Link to buttons page Display in main frame area

30 Create in Visio (either from scratch or web page map and add new objects) Save as.pdf Link to buttons page

31 Slides (that would be presented to an investor group) <=10 Cover slide (graphic logo, business name, your name, date) Outline Purpose of Presentation (vision) Business Overview and explanation of business name Products and/or services of business Website purpose Website navigation scheme Other slides to make your “sales to investors” case Create in PowerPoint Save as.pdf Link to buttons page