Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

Chapter 19 Programming Functions. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives Apply JavaScript rules.
The Web Warrior Guide to Web Design Technologies
Tutorial 6 Working with Web Forms
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 7 Event-Driven.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Computing Concepts Advanced HTML: Tables and Forms.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
There is a certain way that an HTML file should be set up. The HTML section declares a beginning and an ending. Within the HTML, there should be a HEAD.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Glencoe Digital Communication Tools Create a Web Page with HTML Chapter Contents Lesson 4.1Lesson 4.1 Get Started with HTML (85) Lesson 4.2Lesson 4.2 Format.
Creating Tables in a Web Site Using an External Style Sheet HTML5 & CSS 7 th Edition.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
HTML Tables and Forms Creating Web Pages with HTML CIS 133 Web Programming Concepts 1.
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.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
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.
Web Technologies Website Development Trade & Industrial Education
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
The Bean Counter: A JavaScript Program
Learning Objectives Use the Bean Counter application as a model to do the following: Write input elements Create a button table Write an event handler.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and attributes Create.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
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.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Designing a Web Page with Tables. A text table: contains only text, evenly spaced on the Web page in rows and columns uses only standard word processing.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
USING XML AS A DATA SOURCE. Data binding is a process by which information in a data source is stored as an object in computer memory. In this presentation,
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
Chapter 18 A JavaScript Program. Learning Objectives Use the Bean Counter application as a model to do the following: –Write input elements –Create a.
Chapter 22 The Smooth Motion: Case Study in Algorithmic Solving.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
HTML Concepts and Techniques Fifth Edition Chapter 4 Creating Tables in a Web Site.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley What did we learn so far? 1.Computer hardware and software 2.Computer experience.
Creating and Editing a Web Page
What is HTML? HTML is a language for describing web pages. HTML stands for Hyper Text Markup Language HTML is not a programming language, it is a markup.
Positioning Objects with CSS and Tables
Scripting with Client-Side Processing Scripting with Client Side Processing Lesson – Web Technologies Copyright © Texas Education Agency, All rights.
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.
CSC 121 Computers and Scientific Thinking Fall Event-Driven Programming.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Chapter 18 A JavaScript Program. Learning Objectives Use the Bean Counter application as a model to do the following: –Write input elements –Create a.
Section 4.1 Section 4.2 Format HTML tags Identify HTML guidelines
JavaScript is a programming language designed for Web pages.
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
Section 17.1 Section 17.2 Add an audio file using HTML
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
The Smooth Motion: Case Study in Algorithmic Solving
JavaScript Basics What is JavaScript?
Presentation transcript:

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

19-2 Preliminaries Use a basic text editor; fancy formatting will confuse the web browser File format is text; filename extension should be.html –The operating system knows the file will be processed by a web browser To create program, start a file whose first line is and last line is

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-3 Preliminaries (cont'd) Enclose JavaScript text in tags When program is written, save it, then find file on computer and double click it –Web browser should open file and display the page you created

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-4 Important Development Principle We do not try to write our final program as a monolithic one-shot entity We “grow” the program from small initial versions into a final fully functional version –Start with a simple version to basically get the web page set up and the script segment executing (version 0) –Once we see version 0 working, we complicate it some for version 1, then complicate it more for version 2, etc. Test, test, test at every step… make your steps small so you can back up easily when you need to

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-5

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-6

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-7 GUI for the Bean Counter Program This is where we are headed…

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-8 Background for the GUI Review XHTML Basics The Bean Counter All programming in this example is concentrated in the body of the document We use a tag pair in the to set up a default color scheme and font selection for the page Body { background-color: saddlebrown; clor: darkorange; Font-family: helvetica; text-align: center }

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-9 Background for the GUI (cont'd) We can set the color of the headings in the the bean counter Interacting with a GUI –Input facilities like buttons and checkboxes are known as elements of forms –Form tags and must surround all input elements –Form tag has attributes: All our GUI programming will go between these two tags

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-10

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Events and Event Handlers GUI inputs cause events to occur –Event is an indication from the computer (Operating System) that something just happened –User clicking on command button causes "click event" Event handler is program that performs some task in response to event We write event handlers in JavaScript and associate them with the various input elements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Three Input Elements Button –value gives text to be printed on the button –identifier is the name of the element –onclick gives event handler (JavaScript instructions) –Button image is placed in next position in text of XHTML document

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Three Input Elements Text Box –Used to input or output numbers or words –identifier is the name of the element –onchange gives the event handler's JavaScript instructions These program instructions are performed after user enters text –Text input image is placed in next position in text of XHTML program

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Three Input Elements Radio Button –Gives a selection of preprogrammed settings label text –Identifier is the name of the element A group of radio buttons use the same name –label text is shown beside the button –onclick gives the event handler When user clicks button, center darkens (indicating it is set), other radio buttons are cleared, and the instructions of the event handler are performed –Radio button image is placed in the next position in the text of the XHTML document

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Create the Graphical User Interface Bean Counter program is mostly a table of buttons Algorithm for building the table: –Create a button table Program XHTML for a table with a generic button in each cell. Easy to do with Copy/Paste –Delete two buttons Two cells should be empty. Don't delete the cells –Insert text box Replace button for last cell with a text control –Label the buttons Set the value attribute of each button so the label is correct –Primp the interface Check and adjust where necessary

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley GUI for the Bean Counter Program This is where we are headed…

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Create a Button Table –"b" is a placeholder for the button label (we'll fix in Step 4), and ' ' is a placeholder for the event handler we'll write later –Make four copies of the cell and surround them by row tags –Make four copies of the row and surround them by table tags –Save the page and review (test) –Add to the style section for centering table{margin-left: auto; margin-right: auto; text-align: center}

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-18

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Delete the Two Buttons In row 2, cell 4, and row 4, cell 2, remove the –These cells must be empty –Cell can be empty but must still be surrounded by tags to be a cell

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Insert the Text Box Name the text box "price" because that's the information that will be printed Window should be 5 characters wide because no combination of drink inputs will result in a price of more than 4 digits plus decimal point onchange needs a placeholder Button in row 4, cell 4, should be replaced by

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-21

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Label the Buttons Pass through cells and change the value attribute of each button from "b" to its proper label First column is number of shots (1, 2, 3, 4) Second column is sizes (S, T, G) Third column is the drinks (ESPRESSO, LATTE, CAPPUCCINO, AMERICANO) It is easiest to work row-wise rather than column-wise in XHTML tables

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-23

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Primp the Interface Make the buttons the same width –Add spaces in the drink name labels Add color, borders, padding to the table –Modify the global table style background-color: #993300; border-style: solid; border-color: firebrick; border-width: medium; padding: 8px Add border to the price text box –Modify the style attributes in the tag <td style=“border-style: solid; border-width: medium; border-color: red”>

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Event-Based Programming Something should happen as each button is clicked — giving a response to user-caused events Define in JavaScript the actions to be performed when each button is clicked This is called event-based programming

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The onClick Event Handler onclick is the event-handling attribute for the Total button Insert the price computation code (from earlier, with temporary assignments removed) inside the quotes for the onclick attribute It becomes the onclick event handler for that one button

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-27

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley On a Click Event When the barista clicks on the Total button, it causes a click event in the browser The browser looks for the onclick event handler in the XHTML button input tag called “Total” Browser runs those JavaScript program instructions, then waits for the next event

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Shots Button In each case, ask what action should be performed when a particular button is clicked For the first column, specify number of shots –Clicking on the 1 button should cause shots variable to have value 1 –Clicking on the 2 button assigns shots the value 2, etc.

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Size and Drink Buttons Size buttons assign the ounce variable the appropriate value: 8, 12, or 16 Drink variable gets the name of the drink quoted <input type="button" value=" ESPRESSO " onclick=' drink = "espresso" ' /> Single quotes surround the assignment statement, which uses double quotes –Remember that string literals are case-sensitive

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Clear Button and Initializations Clicking on Clear button should reset all variables to their initial values We have not declared or initialized those variables yet Place declarations at start of JavaScript body, enclosed in tags var shots = 1; var drinks = "none"; var ounce = 0;

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Clear Button and Initializations (cont'd) Clear button makes the same assignments as the initialization statements for each variable <input type="button" value="Clear" onclick='shots = 1; drink = "none"; ounce = 0; document.Bean.price.value = "0.00" ' />

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Referencing Data Across Controls When we want a statement in one element to change a value in another element, we must tell the browser how to navigate among the elements Use the dot operator –Provides a means of navigation to the proper object object.property selects the property of the object document.forms[0].price.value = "0.00" this HTML doc form attribute GUI/element

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Changing Window Values Input elements are for both input and output –When the value is reassigned, the window displays the new value, acting as output Displaying the Total –Total event handler outputs the price document.forms[0].price.value = price;

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Critiquing the Bean Counter Numbers versus Money –Final price is shown as number, not currency –Use Math.round to round to two decimal places –Trailing zeros will be dropped, but we won't worry about it Organization –The design and organization makes sense for its application Feedback –There is no feedback about current settings of variables –We could add a window above each column giving the current setting

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19-36

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Recap of the Bean Counter Application The “program” is a collection of small JavaScript code chunks scattered through XHTML source Referencing variables –Placed variable declarations inside the and tags –Referenced data as variables local to a handler ( price ), as variables global to all handlers ( drink ), and as a variable/attribute in another element ( document.forms[0].price.value )

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Bean Counter Recap (cont'd) Program and Test –Incremental process –Produced minimal XHTML program, and tested –Added skeleton table, and tested –Improved table one feature at a time and tested –Wrote JavaScript to solve one event handler at a time No complex tasks Continual testing spots errors immediately

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Bean Counter Recap (cont'd) Assess the Program Design –Critiquing how well the solution fulfilled the need for which it was written –Software should perfectly match the solution requirements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Summary We developed an XHTML page with a JavaScript program in it The program was event-driven XHTML input elements were used to allow a user to trigger events driving the program (through a GUI) JavaScript code is used for the instructions of the event handlers associated with the XHTML elements XHTML and JavaScript are separate languages; they used cooperatively as a GUI (XHTML) and its actions (JavaScript).