The Bean Counter: A JavaScript Program

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
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
Chapter 4 Marking Up With Html: A Hypertext Markup Language Primer.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Computer Science 103 Chapter 4 Advanced JavaScript.
Session 2 Tables and forms in HTML Adapted by Sophie Peter from original document by Charlie Foulkes.
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.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
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.,
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
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.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
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.
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.
1 ADVANCED MICROSOFT EXCEL Lesson 9 Applying Advanced Worksheets and Charts Options.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
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,
Chapter 18 A JavaScript Program. Learning Objectives Use the Bean Counter application as a model to do the following: –Write input elements –Create a.
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
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.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
HTML Concepts and Techniques Fifth Edition Chapter 4 Creating Tables in a Web Site.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
Creating and Editing a Web Page
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
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.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
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.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Chapter 18 A JavaScript Program. Learning Objectives Use the Bean Counter application as a model to do the following: –Write input elements –Create a.
HTML Again GUI Items Originally HTML 4 Copyright © Curt Hill.
Section 4.1 Section 4.2 Format HTML tags Identify HTML guidelines
In this session, you will learn to:
JavaScript is a programming language designed for Web pages.
Section 17.1 Section 17.2 Add an audio file using HTML
JavaScript Functions B. Ramamurthy 11/22/2018.
The Smooth Motion: Case Study in Algorithmic Solving
JavaScript Basics What is JavaScript?
Chapter 7 Event-Driven Pages
Presentation transcript:

The Bean Counter: A JavaScript Program Chapter 19 The Bean Counter: A JavaScript Program

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 <html> and last line is </html> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Preliminaries (cont'd) Enclose JavaScript in tags <script language="JavaScript> </script> 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 © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Background for the GUI Review HTML basics <head> <title> The Bean Counter </title> </head> <body> All programming in this example is concentrated in the <body> </body> Table gives control over where information is displayed <table></table> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Background for the GUI (cont'd) Interacting with a GUI Input facilities like buttons and checkboxes are known as elements of forms Form tags <form> and </form> must surround all input elements Form tag has name attribute: <form name = "Bean"> </form> File ends with </body> </html> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Events and Event Handlers GUI inputs being used causes event to occur Event is an indication from the computer that something just happened User clicking on command button causes "click event" Event handler is program that performs task in response to event Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Three Input Elements Button <input type=button value="label" onClick= " event_handler "> value gives text on button onClick gives event handler (JavaScript instructions) Button image is placed in next position in text of HTML document Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Three Input Elements Text Box Used to input or output numbers or words <input type=text name="identifier" size=6 onChange=" event_handler "> Identifier is the name of the element onChange gives the event handler's JavaScript instructions Program instructions are performed after user enters text Image is placed in next position in text of HTML program Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Three Input Elements Radio Button Gives a selection of preprogrammed settings <input type=radio name="identifier" onClick=" event_handler ">label text Identifier is the name of the element label text is shown beside the button onClick gives the event handler When user clicks button, center darkens (it is set) and the instructions of the event handler are performed Image is placed in the next position in the text of the HTML document Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Create the Graphical User Interface It is mostly a table of buttons Algorithm for building the table: Create a button table. Program HTML 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 Label the buttons Set the value attribute of each button so the label is correct Primp the interface Check and adjust where necessary Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Create a Button Table <td> <input type=button value="b" onClick = ' '> </td> "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 Change default left-justification to center—surround the table with <center></center> tags Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Delete the Two Buttons In row 2, cell 4, and row 4, cell 2, remove the <input…> These cells must be empty Cell can be empty but must still be surrounded by <td></td> tags to be a cell Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Insert the Text Box Name the text box "price" because that's what should 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 <input type=text name="price" value="0.00" size=5 onChange=' '> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 Second column is sizes Third column is the drinks It is easiest to work row-wise rather than column-wise in HTML Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Primp the Interface Notice that the buttons are left-justified in the columns Buttons in last two columns should be centered To revise ESPRESSO entry: <td align="center"> input type=button value = " ESPRESSO " onClick = ' '> </td> Give table a background color <table bgColor="#993300"> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Primp the Interface (cont'd) Add a border around the table as a whole Make a big one-cell table and make our table, the table data for that new table Outline the price box with red <td bgcolor="red"> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Event-based Programming Something should happen as each button is clicked—only in response to user-caused events Define in JavaScript the actions to be performed when each button is clicked Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

The onClick() Event Handler onClick is the event-handling attribute for the Total button Insert the price computation code inside the quotes for the onClick attribute It becomes the onClick event handler Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 Total button input tag Browser runs those instructions, then waits for the next event Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 1 button should cause shots variable to have value 1 <td> <input type = button value = "1" onClick = 'shots = 1'> </td> Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 Single quotes surround the assignment statement, which uses double quotes Remember that string literals are case-sensitive Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 body, enclosed in <script> tags Clear button makes the same assignments as the initialization statements for each variable Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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.Bean.price.value = "0.00" Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Changing the Window 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 price document.Bean.price.value = price; Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

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 © 2006 Pearson Addison-Wesley. All rights reserved.

Recap of the Bean Counter Application Referencing variables Placed in <body> in separate <script> tags because application used many tiny segments of code Referenced data as variables local to a handler, as variables global to all handlers, and as a variable in another element Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Recap of the Bean Counter Application (cont'd) Program and Test Incremental process Produced minimal HTL program, and tested Added skeleton table, and tested Improved table one feature at a time Wrote JavaScript to solve one event handler at a time No complex tasks Continual testing spots errors immediately Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Recap of the Bean Counter Application (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 © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.