HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

Similar documents
CSE 154 LECTURE 8: EVENTS AND TIMERS

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

Fundamentals of Website Development

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

Events: another simple example

CSE 154 LECTURE 9: SUBMITTING DATA (POST)

Introduction to DHTML

CSE 154 LECTURE 9: SUBMITTING DATA (POST)

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

CSC Javascript

1 Form Basics CSC309

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Name Related Elements Type Default Depr. DTD Comment

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

DOM Primer Part 2. Contents

TEXTAREA NN 2 IE 3 DOM 1

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component

JavaScript Handling Events Page 1

CSE 154 LECTURE 8: FORMS

Photo from DOM

Javascript Lecture 23

Web Programming Step by Step

Want to add cool effects like rollovers and pop-up windows?

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

JSF - H:SELECTONERADIO

HTML 5 Tables and Forms

!Accessibility Issues Found

HTML Forms. By Jaroslav Mohapl

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab

Javascript. A key was pressed OR released. A key was released. A mouse button was pressed.

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

Introduction to JavaScript, Part 2

Installation and Configuration Manual

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

Appendix A. XHTML 1.1 Module Reference

Digitizing Sound and Images III Storing Bits

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

CSS Review. Objec(ves. Iden(fy the Errors. Fixed CSS. CSS Organiza(on

Lecture 9 & 10 PHP - II

Chapter 14 - Dynamic HTML: Event Model

IS 242 Web Application Development I

JSF - H:SELECTONEMENU

Continues the Technical Activities Originated in the WAP Forum

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

By the end of this section of the practical, the students should be able to:

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

HTML and JavaScript: Forms and Validation

WCAG2-AA accessibility report for

WCAG2-AA accessibility report for

WCAG2-AA accessibility report for

Client vs Server Scripting

Web Programming Step by Step

Web Designing Course

The ActionScript Markup Language

Unobtrusive JavaScript. Lecture Outline. CSE 190 M (Web Programming), Spring 2008 University of Washington

Outline. Introducing Form. Introducing Forms 2/21/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

Web Design and Application Development

Web GUI Development CSE5544

Q1. What is JavaScript?

CITS1231 Web Technologies

CICS 515 a Internet Programming Week 3. Mike Feeley

WCAG2-AAA accessibility report for

Full file at Tutorial 2: Working with Operators and Expressions

UNIT - III. Every element in a document tree refers to a Node object. Some nodes of the tree are

JavaScript Introduction

JSF - H:PANELGRID. JSF Tag. Rendered Output. Tag Attributes. The h:panel tag renders an HTML "table" element. Attribute & Description.

5-Sep-16 Copyright 2016 by GemTalk Systems LLC 1

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Web Forms. Survey or poll Contact us Sign up for an newsletter Register for an event

HTML Form. Kanida Sinmai

Objec&ves. Review: Databases, SQL, JDBC. The Hack. Join Queries. JavaScript. Web Programming

Internet Explorer HTML 4.01 Standards Support Document

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

Place User-Defined Functions in the HEAD Section

JavaScript Programming Chris Seddon

This tutorial has been designed for beginners in HTML5 to make them understand the basicto-advanced

XHTML Mobile Profile. Candidate Version Feb Open Mobile Alliance OMA-TS-XHTMLMP-V1_ C

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Advanced HTML Scripting WebGUI Users Conference

JavaScript: Events, DOM and Attaching Handlers

EECS1012. Net-centric Introduction to Computing. Lecture Introduction to Javascript

JavaScript II CSCI 311 SPRING 2017

JavaScript: A Crash Course

New Media Production Lecture 7 Javascript

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Phụ lục A. Sơ đồ các đối tượng trong trình duyệt

CITS3403 Agile Web Development Semester 1, 2018

INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT

NAME: name a section of the page TARGET = "_blank" "_parent" "_self" "_top" window name which window the document should go in

Transcription:

Page 1 HTML User Interface Controls CSE 190 M (Web Programming), Spring 2007 University of Washington Reading: Sebesta Ch. 5 sections 5.1-5.7.2, Ch. 2 sections 2.9-2.9.4 Interactive HTML user interfaces in this section, we'll learn how to make user interface controls (buttons, checkboxes, text fields, etc.) in HTML controls are often used in HTML forms (seen later) Javascript is integral to interactivity aspect of controls (event handlers) Document Object Model (DOM) a representation of the current web page as a set of Javascript objects allows you to view/modify page elements in script code DOM tutorial

Page 2 Global DOM objects window : the browser window navigator : info about the web browser you're using screen : info about the screen area occupied by the browser history : list of pages the user has visited document : current HTML page Recall: event handlers <h2 onclick="myfunction();"></h2> HTML elements have special attributes called events Javascript functions can be set as event handlers when you interact with the element, the function will execute an example of event-driven programming event HTML attributes: onabort, onblur, onchange, onclick, ondblclick, onerror, onfocus, onkeydown, onkeypress, onkeyup, onload, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onreset, onresize, onselect, onsubmit, onunload document object and getelementbyid <h2 onclick="makered();">sell</h2> <p id="announce">get it while it's hot!</p> function makered() { var para = document.getelementbyid("announce"); para.style.color = "red"; Sell Get it while it's hot! document object's getelementbyid method returns an object representing the HTML element with the given id attribute (null if not found) DOM objects for all HTML elements contain the following properties: classname, id, style, title

Page 3 DOM style property function enlarge(id) { var element = document.getelementbyid(id); element.style.fontsize = "42pt"; Click me and make me big! style property represents the combined styles that apply to this element contains identical properties to the style properties set in CSS, except that names are changed from hyphenated to capitalized examples: backgroundcolor, borderleftwidth, fontfamily Buttons: <button> <button onclick="alert('hello!');"></button> button's text appears inside button tag JS onclick event handler specifies button's behavior The DOM innerhtml property <button id="b1" onclick="myfunction('i did it!');"></button> <p id="target">this text will be replaced.</p> function myfunction(text) { var p = document.getelementbyid("target"); p.innerhtml = text; This text will be replaced. innerhtml refers to the HTML text inside of an element: <p>this is the innerhtml of the p tag</p> event handler can modify the innerhtml of another element

Page 4 Another <button> example <button id="b1" onclick="addtext();"></button> function addtext() { var button = document.getelementbyid("b1"); button.innerhtml += " narf"; also acceptable in this case: <button onclick="this.innerhtml += ' narf';"></button> Text boxes: <textarea> (DOM) <textarea rows="4" cols="20"> Type your comments here. </textarea> Type your comments here. initial text placed inside textarea tag (optional) optional readonly attribute means text cannot be modified DOM properties: disabled, readonly, value NOTE: get/set area's text using value, NOT innerhtml Practice problem: Shuffle Write the HTML and Javascript code to shuffle the lines of text within a text area whenever a Shuffle button is clicked. shuffling algorithms

Page 5 Drop-down list: <select> (DOM), <option> (DOM) <select> <option>jerry</option> <option>george</option> <option>kramer</option> <option>elaine</option> </select> Jerry option element represents each choice select optional attributes: disabled, multiple, size attach onchange handler to select to cause behavior on each selection <select onchange="alert('you chose ' + this.value);"> Using <select> for lists <select multiple="multiple" size="3"> <option value="jerry">jerry</option> <option value="george">george</option> <option value="kramer">kramer</option> <option value="elaine">elaine</option> <option value="newman">newman</option> <option value="susan">susan</option> </select> Jerry George Kramer DOM properties: disabled, length, multiple, name, selectedindex, size, value (selected item text) DOM methods: add(option, index), remove(index)

Page 6 Option groups: <optgroup> <select> <optgroup label="major Characters"> <option value="jerry">jerry</option> <option value="george">george</option> <option value="kramer">kramer</option> <option value="elaine">elaine</option> </optgroup> <optgroup label="minor Characters"> <option value="newman">newman</option> <option value="susan">susan</option> </optgroup> </select> Jerry what should we do if we don't like the bold italic? Input fields: <input> <input type="text" /><br /> <input type="password" size="12" /> creates many different types of input controls, depending on its type attribute always empty; contains attributes only attributes: accept, alt, disabled, maxlength, name, readonly, size, src, type, value DOM properties for type="text" and type="password": disabled, maxlength, readonly, size, value (text in field) Radio buttons (DOM) <input type="radio" name="creditcards" id="visa" /> <label for="visa">visa</label> <input type="radio" name="creditcards" id="mastercard" /> <label for="mastercard">mastercard</label> <input type="radio" name="creditcards" id="amex" /> <label for="amex">american Express</label> Visa MasterCard American Express grouped by (required) name attribute button's text is a label element with for attribute set to button's id DOM properties: checked, defaultchecked, disabled

Page 7 Checkboxes (DOM) <input type="checkbox" name="toppings" value="lettuce" id="lettuce" /> <label for="lettuce">lettuce</label> <input type="checkbox" name="toppings" value="tomato" id="tomato" /> <label for="tomato">tomato</label> <input type="checkbox" name="toppings" value="pickles" id="pickles" /> <label for="pickles">pickles</label> Lettuce Tomato Pickles name attribute is required use checked="checked" attribute in HTML to initially check the box DOM properties: checked (Boolean), defaultchecked, disabled Grouping input: <fieldset>, <legend> <fieldset> <legend>credit cards:</legend> <input type="radio" name="creditcards" id="visa" /> <label for="visa">visa</label><br /> <input type="radio" name="creditcards" id="mastercard" /> <label for="mastercard">mastercard</label><br /> <input type="radio" name="creditcards" id="amex" /> <label for="amex">american Express</label><br /> </fieldset> Credit cards: Visa MasterCard American Express groups related input fields; legend supplies an optional caption Practice problem: Colored text Write the HTML and Javascript code to present a text area and three on/off options for red, green, and blue. When the user checks each box, it will add or remove that color from the text area's text.