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

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Tutorial 6 Creating a Web Form
End User Computing An Introduction to CSS Sujana Jyothi Research Lab1, Callan Building, Department of Computer Science
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Unit 20 - Client Side Customisation of Web Pages
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Chapter 6 Basic forms 1. Forms and query string 2 form : a group of user input (UI) controls that accepts information from the user and sends the information.
CS4370/6370 Web Development Cascading Style Sheets (CSS)
Web Development & Design Foundations with HTML5
Tutorial 14 Working with Forms and Regular Expressions.
Cascading Style Sheet (CSS) Instructor: Dr. Fang (Daisy) Tang
WEB PAGES: CREATING AND MAINTAINING ** Tom Keane & Mayis SeapanInstructors: HTML Tags to format your text.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
HTML Tables and Forms Creating Web Pages with HTML CIS 133 Web Programming Concepts 1.
Web Page Creation Part II ST: Introduction to Web Interface Design Prof. Angela Guercio.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 2- JavaScript in Action Modern JavaScript Design And Develop Copyright © 2012 by Larry.
HTML 5 Tutorial Chapter 9 Form Attributes. New Form Attributes HTML5 has several new elements and attributes for forms. New form attributes : autocomplete.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
CS 174: Web Programming April 21 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Key question  What are the three standardized core languages used to implement web pages? Write the full name not the abbreviation and describe the “layer”
Image Use. Agenda Ordinary display of image: height, width, alt Rollovers Images as links (remove blue surround) Background images: stretch, tile, xonly/yonly.
Tutorial 14 Working with Forms and Regular Expressions.
Homework for October 2011 Nikolay Kostov Telerik Corporation
Principles of Web Design 6 th Edition Chapter 10 – Data Tables.
Neal Stublen Improvements  New form elements  Assist with validation  Consistency across sites  Changes reduce the need for common.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
HTML. Basic HTML HTML document – HTML headings – to HTML paragraphs – HTML links – HTML images –
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
CO1552 – Web Application Development Cascading Style Sheets.
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
ALBERT WAVERING BOBBY SENG. Week 2: HTML + CSS  Quiz  Announcements/questions/etc  Some functional HTML elements.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CSS Cascading Style Sheets. CSS Advantages Greater typography and page layout control Style is separate from structure Styles can be stored in a separate.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
Cascading Style Sheets (CSS) Within the Enterprise Architecture Framework (EAF) Wes Ziegeler August 3, 2006.
Session I Chapter 1 - Introduction to Web Development
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Advanced Web Development Instructor: Thomas Bombach.
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.
CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
26 HTML Tables … surround table … surround each row … surround each cell … like, but bold and centered by default (for table headings) … table title No.
CS 174: Web Programming September 9 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
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
LING 408/508: Programming for Linguists
ASSIGNMENT POINTS DUE DATE: Monday NOV 30 JAVASCRIPT, INPUT VALIDATION, REGEX See 2 nd slide for Form See 3 rd next slide for the required features.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Tutorial 6 Creating a Web Form
JavaScript and Ajax (JavaScript Dynamic HTML (DHTML)) Week 7 Web site:
A little more JavaScript??. Building a caculator We'll need to learn about the following: – Form buttons. – Applying CSS rules by attribute values. –
CMPE 280 Web UI Design and Development September 7 Class Meeting
>> Form Data Validation in JavaScript
JavaScript, Sixth Edition
The Box Model in CSS Web Design – Sec 4-8
© 2017 Akhilesh Bajaj, All Rights Reserved
The Box Model in CSS Web Design – Sec 4-8
IS333: MULTI-TIER APPLICATION DEVELOPMENT
The University of Tulsa
Presentation transcript:

CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Input Validation  A key use of JavaScript code is input validation.  On the client side, validate user input in form fields before the values are submitted to the server side. Much more more responsive and interactive web pages.  It’s inefficient to have PHP code validate user input on the server side and then generate a new HTML page containing error messages to be displayed in the client side. 2

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Validate Non-Empty Text  HTML:  JavaScript: 3 Name <input type = "text" value = "" id = "name" /> name = document.getElementById("name").value; if (name == "") { errors += "Missing name.\n"; }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak JavaScript Regular Expressions 4

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Validate Phone Number  HTML:  JavaScript: 5 Phone number <input type = "text" value = "(nnn) nnn-nnnn" id = "phone" /> phone = document.getElementById("phone").value; phoneRE = /^\(\d{3}\) *\d{3}-\d{4}$/; if (!phone.match(phoneRE)){ errors += "Invalid phone number. " + "Example: (999) \n"; } JavaScript quotes regular expressions with the forward /.

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Validate Phone Number, cont’d 6 /^\(\d{3}\) *\d{3}-\d{4}$/ three digits four digits left parenright parenhyphen any number of blanks (including none) start of string end of string  What is the purpose of specifying both the start of the string ( ^ ) and the end of the string ( $ )? The entire string must match (nothing before or after).

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Validate Address  HTML:  JavaScript: 7 address <input type = "text" value = id = " " /> = document.getElementById(" ").value; RE = if (! .match( RE)){ errors += "Invalid address. " + "Should be }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Validate Address, cont’d 8 start of string end of signdot at least one character at least one character 2, 3, or 4 characters Demo

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak JavaScript Regular Expressions, cont’d  Use parentheses in a regular expression to group and store a pattern. Example: /(Bora){2}/ matches BoraBora  Use \1, \2, etc. to recall the first, second, etc. match of a stored pattern. Example: /^(.)(.).*\1\2$/ matches any string that begins and ends with the same two characters, such as BoraBoraBo  What can /^.* $/ match? 9

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Input Validation with HTML5 and CSS3  CSS pseudo-classes: :required :invalid 10 input:required { border: 1px solid blue; } input:invalid { color: white; background-color: red; }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak Input Validation with HTML5 and CSS3, cont’d 11 Name: <input type = "text" value = "" id = "name" required /> Phone number: <input type = "text" placeholder = "(999) " pattern = "^\(\d{3}\) *\d{3}-\d{4}$" id = "phone" required /> address: <input type = "text" placeholder = pattern = id = " " /> No JavaScript required! HTML quotes regular expressions like any other string. Demo

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak New HTML5 Input Types  HTML5 has new input types. Automatic built-in input validation. Special effects with some browsers. 12 date time datetime datetime-local week month color number range search tel url NOTE: Different browsers implement these input types differently (Chrome does best).

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak New HTML5 Input Types, cont’d  Chrome browser: 13 Range: <input type = "range" id = "range" min = "0" max = "256" value = "128" />

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak New HTML5 Input Types, cont’d  Chrome browser: 14 Color: <input type="color" id = "color" /> Demo

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak JavaScript Event Handlers 15

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak JavaScript Bingo Program  Demonstrate the coordination of HTML, CSS, and JavaScript. Adapted from JavaScript, 9 th edition by Tom Negrino and Dori Smith Peachpit Press, 2015 ISBN Demo How would you implement this Bingo card?

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.html  The card is an HTML table. Each cell has an id and is initially blank. 17 B I N G O Free

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.js 18 window.onload = initAll; function initAll() { document.getElementById("reload").onclick = anotherCard; newCard(); } function newCard() { for (var i = 0; i < 24; i++) { setSquare(i); } }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.js, cont’d  Note that on a Bingo card, the numbers are distributed randomly as follows: Column B: 1 – 15 Column I: 16 – 30 Column N: 31 – 45 Column G: 46 – 60 Column O: 61 – 75  There are no repeated numbers on a card. 19

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.js, cont’d 20 var colPlace = new Array(0, 0, 0, 0, 0, // B 1, 1, 1, 1, 1, // I 2, 2, 2, 2, // N 3, 3, 3, 3, 3, // G 4, 4, 4, 4, 4); // O var usedNums = new Array(76); function setSquare(thisSquare) { var currSquare = "square" + thisSquare; var colBasis = colPlace[thisSquare]*15; var newNum; do { newNum = colBasis + getNewNum() + 1; } while (usedNums[newNum]); usedNums[newNum] = true; document.getElementById(currSquare).innerHTML = newNum; document.getElementById(currSquare).className = ""; document.getElementById(currSquare).onmousedown = toggleColor; }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.js, cont’d 21 function getNewNum() { return Math.floor(Math.random()*15); } function anotherCard() { for (var i = 1; i < usedNums.length; i++) { usedNums[i] = false; } newCard(); return false; }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.js 22 function toggleColor(evt) { if (evt) { var thisSquare = evt.target; } else { var thisSquare = window.event.srcElement; } if (thisSquare.className == "") { thisSquare.className = "pickedBG"; } else { thisSquare.className = ""; } } Dynamically change the cell’s class.

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak bingo.css 23 body { background-color: white; color: black; font-size: 20px; font-family: "Lucida Grande", Verdana, Arial, Helvetica, sans-serif; } h1, th { font-family: Georgia, "Times New Roman", Times, serif; } h1 { font-size: 28px; }

Computer Science Dept. Spring 2015: February 26 CS 174: Web Programming © R. Mak 24 bingo.css, cont’d table { border-collapse: collapse; } th, td { padding: 10px; border: 2px black solid; text-align: center; width: 20%; } #free,.pickedBG { background-color: LightCoral; }