CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
Advertisements

Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
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.
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
1 COMM 1213 H1 COMP 4923 X1 JavaScript 2 (Readings: Ch. 12, 13, 14 Knuckles)
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Chapter 2 Developing a Web Page. A web page is composed of two distinct sections: –The head content –The body Creating Head Content and Setting Page Properties.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
JavaScript, Fourth Edition
Tutorial 10 Programming with JavaScript
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 174: Web Programming August 31 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
XP Tutorial 8 Adding Interactivity with ActionScript.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CS 174: Web Programming October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
HTML Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
CMPE 280 Web UI Design and Development September 7 Class Meeting
Introduction to.
Chapter 5 Validating Form Data with JavaScript
Applied Component I Unit II Introduction of java-script
Tutorial 10 Programming with JavaScript
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
WEB PROGRAMMING JavaScript.
Integrating JavaScript and HTML
© 2015, Mike Murach & Associates, Inc.
Introduction to JavaScript
HTML Forms What are clients? What are servers?
Introduction to JavaScript
CMPE 280 Web UI Design and Development September 10 Class Meeting
Presentation transcript:

CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak MySQL Text Functions  Also: One-way encryption Returns a 40-character string. 2 SHA1( string ) PHP and MySQL for Dynamic Web Sites, 4 th ed. by Larry Ullman Peachpit Press, 2012 ISBN

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak MySQL Text Functions, cont’d 3 mysql> select concat(first, ' ', last) -> from people; | concat(first, ' ', last) | | Charles Jones | | Mary Adams | | Susan Miller | | Roger Brown | | Leslie Adamson | rows in set (0.00 sec) mysql> select concat(first, ' ', last) as name -> from people; | name | | Charles Jones | | Mary Adams | | Susan Miller | | Roger Brown | | Leslie Adamson | rows in set (0.00 sec) alias

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak MySQL Numeric Functions 4 SELECT CONCAT('$', FORMAT(5639.6, 2)) AS cost; PHP and MySQL for Dynamic Web Sites, 4 th ed. by Larry Ullman Peachpit Press, 2012 ISBN

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak MySQL Date and Time Functions 5 No arguments. PHP and MySQL for Dynamic Web Sites, 4 th ed. by Larry Ullman Peachpit Press, 2012 ISBN

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak MySQL Date and Time Functions, cont’d 6  Data types that store both a date and time: DATETIME and TIMESTAMP  Data type that stores just the date: DATE  Data type that stores just the year: YEAR SELECT DATE(registration_date) AS Date FROM users ORDER BY registration_date DESC LIMIT 1; SELECT DAYNAME(registration_date) AS Weekday FROM users ORDER BY registration_date ASC LIMIT 1; PHP and MySQL for Dynamic Web Sites, 4 th ed. by Larry Ullman Peachpit Press, 2012 ISBN

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Formatting the Date and Time 7 Return the current date and time as Month DD, YYYY - HH:MM : Select the address and date registered, ordered by date registered, formatting the date as Weekday (abbreviated) Month (abbreviated) Day Year, for the last five registered users: PHP and MySQL for Dynamic Web Sites, 4 th ed. by Larry Ullman Peachpit Press, 2012 ISBN

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak OK, Back to the Client Side 8 Don’t get dizzy!

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak The Document Object Model (DOM)  Your web browser represents the contents of an HTML page internally using the Document Object Model (DOM). 9

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak The DOM, cont’d  Several key objects of the DOM are children of the special window object. Some important children of window : 10 ObjectRepresentsNotes document Current HTML pageMost commonly scripted object location Current page URL Change location.href to move to another page history List of recently visited pages Access to view previously visited pages status Browser status barUse to set a message in the status bar

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Chrome and the DOM  Use the Chrome browser’s Developer Tools to manually manipulate the DOM.  Load any web page into the Chrome browser. View  Developer  Developer Tools Console tab  Enter Chrome displays the valid choices in a drop-down menu after you type each period. 11 document.body.style.backgroundColor="yellow" Demo Note: CSS uses background-color but DOM uses backgroundColor.

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Introduction to JavaScript 12 PHPJavaScript WhereServer side: web serverClient side: web browser SyntaxSimilar to CSimilar to Java PurposeAccess user’s form input data Access back-end data stores Generate new HTML pages Validate user’s form input data Provide interactivity Modify existing HTML pages  You can write JavaScript code that directly manipulates the DOM.

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Example JavaScript Code 13 Background Color #1 Color buttons <input type="button" value="Red" onclick="document.body.style.backgroundColor='red'" /> <input type="button" value="Green" onclick="document.body.style.backgroundColor='green'" /> <input type="button" value="Blue" onclick="document.body.style.backgroundColor='blue'" /> Button events Event handlers js/backgroundcolor1.html Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Example JavaScript Function 14 Background Color #2 function changeBGColor(color) { document.body.style.backgroundColor = color; } Color buttons <input type="button" value="Red" onclick="changeBGColor('red')" /> <input type="button" value="Green" onclick="changeBGColor('green')" /> <input type="button" value="Blue" onclick="changeBGColor('blue')" /> js/backgroundcolor2.html Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak JavaScript Variables  JavaScript variables are dynamically typed. The type of a variable’s value is determined at run time. What is the value of sum in each example? 15 var x = "1"; var y = "2"; var sum = x + y; var x = 1; var y = 2; var sum = x + y;

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Obtaining Text Input Field Values 16 User input First number: Second number: <input type="button" value="Add version 1" onclick="add1()" /> <input type="button" value="Add version 2" onclick="add2()" /> js/adds1.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Obtaining Text Input Field Values, cont’d 17 Add Versions #1 function add1() { var x = document.getElementById("first").value; var y = document.getElementById("second").value; var sum = x + y; alert(x + " + " + y + " = " + sum); } function add2() { var x = parseInt(document.getElementById("first").value); var y = parseInt(document.getElementById("second").value); var sum = x + y; alert(x + " + " + y + " = " + sum); } Demo js/adds1.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Modifying the DOM Output will appear here. js/adds2.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Modifying the DOM, cont’d function outputSum(x, y) { var sum = x + y; document.getElementById("outputDiv").innerHTML = " " + x + " + " + y + " = " + sum + " "; } function add1() { var x = document.getElementById("first").value; var y = document.getElementById("second").value; outputSum(x, y); }... Demo js/adds2.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Viewing Generated Source Code  Use JavaScript to modify the DOM via an object’s innerHTML property. The browser’s View Source command shows the original unmodified HTML.  Use the browser’s Inspect Element command instead to see the modified HTML. 20 Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Checkbox Values 21 Select one or more colors Red Green Blue <input type="button" value="Show colors" onclick="showColors()" /> Output will appear here. js/checkbox.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Checkbox Values, cont’d function showColors() { var cbred = document.getElementById("cbred"); var cbgreen = document.getElementById("cbgreen"); var cbblue = document.getElementById("cbblue"); var output = " You chose:"; if (cbred.checked) output += " Red"; if (cbgreen.checked) output += " Green"; if (cbblue.checked) output += " Blue"; output += " "; document.getElementById("outputDiv").innerHTML = output; } js/checkbox.html Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Radio Button Values 23 Select a color Red Green Blue <input type="button" value="Show color" onclick="showColor()" /> Output will appear here. js/radio.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Radio Button Values, cont’d function showColor() { var colors = document.getElementsByName("colors"); var output = " You chose:"; for (i = 0; i < colors.length; i++) { if (colors[i].checked) { output += " " + colors[i].value; } } output += " "; document.getElementById("outputDiv").innerHTML = output; } js/radio.html Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Select Menu Value 25 Select a color Red Green Blue <input type="button" value="Change color" onclick="changeBGColor()" /> js/backgroundcolor3.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Select Menu Value, cont’d function changeBGColor() { var color = document.getElementById("colorChooser").value; document.body.style.backgroundColor = color; } js/backgroundcolor3.html Demo

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Multiple Selection Values 27 Select one or more colors <select id="colorChooser" size = "3" multiple="multiple"> Red Green Blue <input type="button" value="Show colors" onclick="showColors()" /> Output will appear here. js/multisel.html

Computer Science Dept. Fall 2015: September 28 CS 174: Web Programming © R. Mak Multiple Selection Values, cont’d function showColors() { var chooser = document.getElementById("colorChooser"); var output = " You chose:"; for (i = 0; i < chooser.length; i++) { if (chooser[i].selected) { output += " " + chooser[i].value; } } output += " "; document.getElementById("outputDiv").innerHTML = output; } js/multisel.html Demo