More Event-Driven Programming Chapter 19. 2 Exercise Make a button whose label toggles between "on" and "off".

Slides:



Advertisements
Similar presentations
>> Introduction to HTML: Forms. Introduction to HTML 5 Important HTML Tags HTML tags and attributes Images Hyperlinks Lists –{ordered | unordered | definition}
Advertisements

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.
Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
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.
JavaScript- with, this. Short cut using with In the previous exercise function mult() { first=parseFloat(document.simpleForm.num1.value); second=parseFloat(document.simpleForm.num2.value);
Form Basics CS Web Data  Most interesting web pages revolve around data  examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes  can.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
XHTML Forms for Data Collection and Submission Chapter 5.
JavaScript “Hello World” in Microsoft Visual Studio August 2012.
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
CSE 154 LECTURE 9: FORMS. Web data most interesting web pages revolve around data examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes can.
Principles of Web Design 6 th Edition Chapter 11 – Web Forms.
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.,
Tutorial #9 – Creating Forms. Tutorial #8 Review – Tables Borders (table, gridlines), Border-collapse: collapse; empty-cells: show; and rowspan, colspan.
© 2010 Delmar, Cengage Learning Chapter 7 Using Styles and Style Sheets for Design.
HTML Forms What is a form.
Chapter 3 Working with Text and Cascading Style Sheets.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 12 – Microsoft FrontPage Express Outline 12.1Introduction 12.2Microsoft FrontPage Express.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Week 10.  Form controls  Parent containing element for other form control elements  Requires method and action attributes to process the information.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
Working with Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 5.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
HTML Forms.
PHP Form Introduction Getting User Information Text Input.
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
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.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Text and Cascading Style Sheets.
Iteration Chapter Iteration = Repetition 3 Looping Via The for Loop for loop: A block of code that executes a group of statements repeatedly until.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Web Foundations WEDNESDAY, NOVEMBER 20, 2013 LECTURE 32: DREAMWEAVER SLIDE SHOW AND GOOGLE MAP.
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
Intro to Forms  HTML forms are used to gather information from end-users.  A form can contain elements like radio- buttons, text fields, checkboxes,
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
JavaScript Challenges Answers for challenges
Radio Buttons.  Quiz  Radio Buttons  Check boxes 2.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
Lecture 8: Events and timers
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
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.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
Check Boxes. 2 Check boxes  Image from:  HTML:  Each box gets it's own.
CSD 340 (Blum)1 Introducing Text Input elements and Ifs.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
HTML FORM. Form HTML Forms are used to select different kinds of user input. HTML forms are used to pass data to a server. A form can contain input elements.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED FORMS.
Changing CSS Styles via JavaScript No readings?. 2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Week-12 (Lecture-1) Cascading Style Sheets (CSS): describe how documents are presented on screens. Types of Style Sheets: External Style Sheet - Define.
Chapter 8: Writing Graphical User Interfaces
Objectives Design a form Create a form Create text fields
Lecture 9: Events and timers
HTML Forms and User Input
Web Systems Development (CSC-215)
Creating Form Elements
© 2015, Mike Murach & Associates, Inc.
Lecture 7: Unobtrusive JavaScript
Events: Changed and Input
BIT116: Scripting Radio Buttons.
Lecture 8: Events and timers
Lecture 7: Unobtrusive JavaScript
Murach's JavaScript and jQuery (3rd Ed.)
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

More Event-Driven Programming Chapter 19

2 Exercise Make a button whose label toggles between "on" and "off".

3 HTML snippet: JavaScript file: Solution <input type="button" id="toggle" value="on" onclick="flip();" /> function flip() { var current = document.getElementById("toggle").value; if (current == "on") { document.getElementById("toggle").value = "off"; } else { document.getElementById("toggle").value = "on"; }

4 Drop-Down List: Menu of choices that collapse and expand. Each choice is represented by element. Example: When you select an option, the selected option label is stored in document.getElementById(" ").value. Rock Hard place Brick wall

5 Change Event Change event handler is set by onchange attribute Example: JavaScript file: Rock Hard place Brick wall function showPick() { var choice = document.getElementById("choices").value; alert("You picked: " + choice); }

6 Radio Button: Set of mutually exclusive choices Attribute type must be set to "radio" Attribute name must be the same for all the choices Example: Poor usability: Must click exactly on circle to activate radio button. MasterCard Visa Discover

7 Text Labels: When used with radio buttons, makes entire label clickable for improved usability. Example: MasterCard Visa Discover

8 Exercise Using the three radio buttons from the previous slides, write code to pop up a box when the user activates a radio button.

9 HTML: First Attempt <input type="radio" name="cards" id="cards" value="MasterCard" onchange="showCard();" />MasterCard <input type="radio" name="cards" id="cards" value="Visa" onchange="showCard();" />Visa <input type="radio" name="cards" id="cards" value="Discover" onchange="showCard();" />Discover Remember, the id attribute has to be unique across all HTML elements!

10 HTML: Second Attempt <input type="radio" name="cards" id="cards1" value="MasterCard" onchange="showCard();" />MasterCard <input type="radio" name="cards" id="cards2" value="Visa" onchange="showCard();" />Visa <input type="radio" name="cards" id="cards3" value="Discover" onchange="showCard();" />Discover How will showCard know which button was clicked?

11 HTML: Third Attempt <input type="radio" name="cards" id="cards1" value="MasterCard" onchange="showCard1();" />MasterCard <input type="radio" name="cards" id="cards2" value="Visa" onchange="showCard2();" />Visa <input type="radio" name="cards" id="cards3" value="Discover" onchange="showCard3();" />Discover

12 JavaScript: First Attempt function showCard1() { var value = document.getElementById("cards1").value; alert("You picked: " + value); } function showCard2() { var value = document.getElementById("cards2").value; alert("You picked: " + value); } function showCard3() { var value = document.getElementById("cards3").value; alert("You picked: " + value); } Very repetitive… can we do better?

13 JavaScript: Solution function showCard1() { var value = document.getElementById("cards1").value; alert("You picked: " + value); } function showCard2() { var value = document.getElementById("cards2").value; alert("You picked: " + value); } function showCard(num) { var value = document.getElementById("cards" + num).value; alert("You picked: " + value); } id

14 HTML: Solution <input type="radio" name="cards" id="cards1" value="MasterCard" onchange="showCard(1);" />MasterCard <input type="radio" name="cards" id="cards2" value="Visa" onchange="showCard(2);" />Visa <input type="radio" name="cards" id="cards3" value="Discover" onchange="showCard(3);" />Discover

15 Changing Your Inner HTML document.getElementById(" ").innerHTML

16 HTML snippet: JavaScript file: Changing Your Inner HTML Name: Hello, world! function update() { var name = document.getElementById("name").value; var newText = "Hello, " + name + " !"; document.getElementById("text").innerHTML = newText; }

17 Generic inline element Example: JavaScript file: Inline Section: Name: Dear Google, Please give me a job. function update() { var name = document.getElementById("name").value; document.getElementById("company").innerHTML = name; }

18 You can style a diverse group of HTML elements using the class attribute.  Elements with the same class attribute will be styled the same way. Example CSS rule for highlight class: For more information, see:  Extra: Class Style.highlight { background-color: yellow; }