Web-based Application Development Lecture 17 March 16, 2006 Anita Raja.

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

The Web Wizards Guide To JavaScript Chapter 3 Working with Forms.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Web-based Application Development Lecture 9 February 7, 2006 Anita Raja.
JavaScript Forms Form Validation Cookies CGI Programs.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Web-based Application Development Lecture 13 February 21, 2006 Anita Raja.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Web-based Application Development Lecture 18 March 21, 2006 Anita Raja.
Computer Science 103 Chapter 4 Advanced JavaScript.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Making Decisions.
Web-based Application Development Lecture 14 February 23, 2006 Anita Raja.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Introduction to JavaScript for Python Programmers
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
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.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Copyright ©2005  Department of Computer & Information Science Introducing DHTML & DOM: JavaScript & Forms.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
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.
Using Client-Side Scripts to Enhance Web Applications 1.
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.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Flow of Control Part 1: Selection
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Web-based Application Development Lecture 11 February 14, 2006 Anita Raja.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
Chapter 5: More on the Selection Structure
JavaScript, Fourth Edition
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
The Web Wizard’s Guide To JavaScript Chapter 3 Working with Forms.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
Drop-down box. Objectives Learn the HTML syntax of a drop-down list javascript properties of a list/menu: length options selectedIndex The location sub-object.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
Chapter 4 The If…Then Statement
Section 17.1 Section 17.2 Add an audio file using HTML
Programming the Web using XHTML and JavaScript
Programming the Web using XHTML and JavaScript
The Web Wizard’s Guide To JavaScript
© 2015, Mike Murach & Associates, Inc.
Web Development Using ASP .NET
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Web Programming and Design
Presentation transcript:

Web-based Application Development Lecture 17 March 16, 2006 Anita Raja

Programming the Web using XHTML and JavaScript Chapter 12 Increasing the Interactivity

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long3 Conditional Statements So far…  Input some data  Output some data  Used variables to store information  Modified information & page characteristics Basically straight line processing Now, respond to user’s input and make choices

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long4 Conditional Statements Conditional statement  Poses a question that is  Unambiguously true or false then  Executes one set of statements if true and  Optionally executes a different set if false

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long5 Conditional Statements Basic syntax (pseudocode): if some condition is true execute these statements otherwise execute these statements Optional

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long6 Conditional Statements JavaScript syntax: if (…) { … } Keyword Conditional statement Statement(s) to be executed if condition is true Defines block Defines conditional statement

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long7 Conditional Statements The question involves a comparison defined by a relational operator var result = 12 … if ( result == 12 ) { … } Equality operator – a test Assignment operator – an action

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long8 Conditional Statements Ch12-Ex-01

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long9 Conditional Statements Relational Operators SymbolMeaning <Less than >Greater than <=Less than or equal to >=Greater than or equal to !=Not equal to ==Equal to

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long10 Conditional Statements Condition syntax: operand operator operand variable operator variable result1 <= result2 variable operator constant result1 != 12

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long11 Conditional Statements Program flow statement x statement y if (condition is true) statement a statement z

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long12 Conditional Statements Program flow statement x statement y if (condition is false) statement a statement z

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long13 Conditional Statements One way or another, statement z is being executed statement x statement y if (condition is false) statement a statement z if statement

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long14 Conditional Statements Ch12-Ex-02

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long15 Conditional Statements JavaScript syntax (optional): if (…) statement or if (…) { statement(s) } or if (…) { statement(s) }

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long16 Conditional Statements JavaScript syntax (optional): if (…) { … } else { … } if clause else clause

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long17 Conditional Statements Ch12-Ex-03

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long18 Conditional Statements Compound conditionals if (…) { … } else if (…) { … }

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long19 Conditional Statements Ch12-Ex-04

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long20 Conditional Statements Nested conditionals if (firstNum > 12) { if (secondNum < 25) { alert(“Number is between 12 and 25”) } statement x Nested conditionals if (firstNum > 12) { if (secondNum < 25) { alert(“Number is between 12 and 25”) } } statement x

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long21 Conditional Statements Nested conditionals if (firstNum > 12) { if (secondNum < 25) { alert(“Number is between 12 and 25”) } else { alert(“The number is out of bounds”) } statement x

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long22 Conditional Statements Nested conditionals if (firstNum > 12) { if (secondNum < 25) { alert(“Number is between 12 and 25”) } else { alert(“The number is out of bounds”) } statement x

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long23 Conditional Statements Nested conditionals if (firstNum > 12) { if (secondNum < 25) { alert(“Number is between 12 and 25”) } else { alert(“The number is out of bounds”) } else { alert(“The number is out of bounds”) } statement x

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long24 Conditional Statements Logical operators  “and” - &&  “or” - ||  “not” - !

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long25 Conditional Statements Logical operators if ( (firstNum > 12) && (secondNum < 25) ) { alert(“Number is between 12 and 25”) } else { alert(“The number is out of bounds”) } statement x

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long26 Conditional Statements Truth tables Prop. 1 (type)TF Prop. 2 T F

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long27 Conditional Statements “Today is Friday and we’re in class” Today is Friday ANDTF We’re in class T F TF FF

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long28 Conditional Statements “Today is Friday or we’re in class” Today is Friday ORTF We’re in class T F TT TF

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long29 Conditional Statements “Today is Friday” Today is Friday TF NOT TF

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long30 Conditional Statements Using “not” var found searchDatabase(found) if (found) alert(“Found it”) else alert(“Item not found”)

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long31 Conditional Statements Using “not” var found searchDatabase(found) if (found==true) alert(“Found it”) else alert(“Item not found”)

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long32 Conditional Statements Using “not” var found searchDatabase(found) if (! found) alert(“Item not found”) else alert(“Found it”)

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long33 Conditional Statements Using “not” var found searchDatabase(found) if (found == false) alert(“Item not found”) else alert(“Found it”)

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long34 Conditional Statements Using “not” var found searchDatabase(found) if (found != true) alert(“Item not found”) else alert(“Found it”)

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long35 Check Boxes Captures user responses  To multiple Yes/No, True/False situations  Basic syntax: <input type = “checkbox” name = “perlCB” checked = “checked” />  Can check as many as you like

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long36 Check Boxes Each check box is an object Each has a checked property  Value can be true or false document.formName.checkboxName.checked Ch12-Ex-05

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long37 Check Boxes Check boxes include an onclick event Ch12-Ex-06

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long38 Radio Buttons Captures user response  To a multiple choice, mutually exclusive situation  Basic syntax: <input type = “radio” name = “sodaRB” />  Can check one and only one within the group having the same name

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long39 Radio Buttons Example: Coke Pepsi Sprite Beer

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long40 Radio Buttons How to test which was selected? Use array element notation: document.formName.sodaRB[0] document.formName.sodaRB[1] … document.formName.sodaRB[n] Ch12-Ex-07

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long41 Pop-Up Menus Only appears when the user selects the menu  So it doesn’t take up space unless needed  Makes them somewhat better than radio buttons when used for a similar purpose

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long42 Pop-Up Menus Created with a form Uses select and option elements: … Creates the menu Defines the individual menu choices

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long43 Pop-Up Menus Ch12-Ex-08

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long44 Pop-Up Menus Menu objects have a selectedIndex property  The first menu item’s index is zero  The second menu item’s index is one, etc. The full name of the property is document.formName.selectName.selectedIndex Use an if statement to find out which menu item was selected

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long45 Pop-Up Menus To make the menu work we’ll add:  Some explanatory text  A button to invoke a function  A function to do something when you select a menu item Ch12-Ex-09

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long46 Pop-Up Menus The element includes a value attribute: Coke Referred to by: document.formName.selectName.options[n].value Ch12-Ex-10

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long47 Pop-Up Menus Sometimes you might not want to give one item preference So include a dummy item to start Ch12-Ex-11

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long48 Pop-Up Menus On the other hand perhaps you’d like a default choice Add selected=“selected” to option Ch12-Ex-12

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long49 Pop-Up Menus Quick links menus can be created using:  The value attribute to hold URLs for each option  The onchange event handler for the select element Ch12-Ex-13

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long50 More on forms … Include name attributes because The general form for information submitted via a form is: Name_Of_Form_Element = Value_Of_Information_Entered Ch12-Ex-14

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long51 More on forms …

ITIS /24/2003 7:57 PMCopyright © 2003 by N.B. Long52 Assignment Debugging Exercise, p. 364 Correct errors Add features to the form to Post corrected document to your Web space as “Lagerstrom-Ch-12.html” Grade based on:  Appearance  Technical correctness of code  Proper results