cse 3345 - graphical user interfaces

66
CSE 3345 - Graphical User Interfaces Lecture 2 – HTML + Forms

Upload: octavia-gillespie

Post on 04-Jan-2016

29 views

Category:

Documents


1 download

DESCRIPTION

CSE 3345 - Graphical User Interfaces. Lecture 2 – HTML + Forms. Giving more meaning to content. Professor X Kitty Pride Scott Summers. vs. Professor X Kitty Pride - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE 3345 - Graphical User Interfaces

CSE 3345 - Graphical User Interfaces

Lecture 2 – HTML + Forms

Page 2: CSE 3345 - Graphical User Interfaces

CSE 3345 2

Giving more meaning to contentProfessor XKitty PrideScott Summers

<class> <teacher>Professor X</teacher> <students> <student age=“17”>Kitty Pride</student> <student age=“16”>Scott Summers</student> </students></class>

vs

Page 3: CSE 3345 - Graphical User Interfaces

CSE 3345 3

Web UIs

Generally consist of 3 parts

1. Structure2. Presentation3. Behavior

Page 4: CSE 3345 - Graphical User Interfaces

CSE 3345 4

3 Parts of UI

StructureSpecifies what the different parts of the content are and how they are related

PresentationHow the content should be displayed

BehaviorHow the content reacts and changes based on user interaction

Page 5: CSE 3345 - Graphical User Interfaces

CSE 3345 5

3 Parts of UI

Structure == HTML

Presentation == CSS

Behavior == Javascript

Page 6: CSE 3345 - Graphical User Interfaces

Web Uis

A different analogy1. Nouns2. Adjectives3. Verbs

“The big green ball bounces up and down.”

Page 7: CSE 3345 - Graphical User Interfaces

Web Uis

A different analogy1. Nouns - HTML2. Adjectives - CSS3. Verbs - Javascript

“The big green ball bounces up and down.”

Page 8: CSE 3345 - Graphical User Interfaces

CSE 3345 8

Separation of content

• Modern best practice says that each should be separate and only used for its intended purpose

Page 9: CSE 3345 - Graphical User Interfaces

CSE 3345 9

Why?

1. Flexibility2. Re-usability3. Ease of debugging4. Cleaner code5. Maintainability6. Graceful Degradation

Page 10: CSE 3345 - Graphical User Interfaces

HTML

HTML

CSS

Javascript

UI

Separation of Slides

Page 11: CSE 3345 - Graphical User Interfaces

HTML

Page 12: CSE 3345 - Graphical User Interfaces

CSE 3345 12

HTML Quick facts

• HTML – Hyper Text Markup Language• Largely based on SGML• Created by Tim Berners-Lee at CERN

Page 13: CSE 3345 - Graphical User Interfaces

CSE 3345 13

What is HTML

• The structure of a web page• The content which makes up a web page• A text-formatted language

Page 14: CSE 3345 - Graphical User Interfaces

CSE 3345 14

What HTML is NOT

• A programming language• Presentation• Behavior

Page 15: CSE 3345 - Graphical User Interfaces

CSE 3345 15

Why use HTML

• Gives developers the ability to add semantic meaning to their content.

semantic - Relating to meaning in language or logic.

Page 16: CSE 3345 - Graphical User Interfaces

CSE 3345 16

Giving more meaning to contentProfessor XKitty PrideScott Summers

<class> <teacher>Professor X</teacher> <students> <student age=“17”>Kitty Pride</student> <student age=“16”>Scott Summers</student> </students></class>

vs

Page 17: CSE 3345 - Graphical User Interfaces

CSE 3345 17

Why use HTML

• Provides the foundation for users to skin their web pages with CSS and add logic with Javascript.

Page 18: CSE 3345 - Graphical User Interfaces

CSE 3345 18

HTML element review

• <h1>-<h6>• <a>• <p>• <table>, <tr>, <th>, <td>• <img>• <div>, <span>• <form>• <input>

Page 19: CSE 3345 - Graphical User Interfaces

CSE 3345 19

Universal HTML Attributes

• id – an unique identifier to the element• class – assigns one or more class names to the

element

Page 20: CSE 3345 - Graphical User Interfaces

CSE 3345 20

id

• Unique – only one

Page 21: CSE 3345 - Graphical User Interfaces

CSE 3345 21

class

• Shared among many elements

Page 22: CSE 3345 - Graphical User Interfaces

CSE 3345 22

Adding Structure

• Try to find an appropriate HTML element for your content.– Use <p> for text– Use <a> for links

• The div and span element in conjunction with id and class attributes offer a generic method for adding structure to documents.

Page 23: CSE 3345 - Graphical User Interfaces

CSE 3345 23

Grouping Elements

• Use <div> and <span> to generically organize or style content in your HTML document.

<div id=“pbj” class=“directions”> <h2>How to make PB&J Sandwiches</h2> <ol> <li><span class=“step”>Step 1:</span> do this</li> </li><span class=“step”>Step 2:</span> do that</li> </ol></div>

Page 24: CSE 3345 - Graphical User Interfaces

CSE 3345 24

DIV vs SPAN

• Div is a block element• Span is an inline element

Other than this, these elements provide no other presentational impact (Unless styled with CSS).

See example explanation here.

Page 25: CSE 3345 - Graphical User Interfaces

CSE 3345 25

Why group elements?

• Grouping elements helps structure your document when creating sections of content

Page 26: CSE 3345 - Graphical User Interfaces

CSE 3345 26

More specific elements for organizing content

Element Description<body> Represents the main content of an HTML document. There

is only one <body> element in a document.

<section> Defines a section in a document.

<nav> Defines a section that contains only navigation links.

<article> Defines self-contained content that could exist independently of the rest of the content.

<aside> Defines some content loosely related to the page content. If it is removed, the remaining content still makes sense.

<h1>,<h2>,<h3>,<h4>,<h5>,<h6> Heading elements implement six levels of document headings; <h1> is the most important and <h6> is the least. A heading element briefly describes the topic of the section it introduces.

<header> Defines the header of a page or section. It often contains a logo, the title of the Web site, and a navigational table of content.

Page 27: CSE 3345 - Graphical User Interfaces

CSE 3345 27

Bad HTML• <blink> - makes text blink • <marquee> - makes text scroll• <b> - makes text bold• <u> - makes text underlined

• <font> - changes font family, color, and size• <i> - makes text italic• <center> - centers text

• <big> -Makes text BIG• <small> - Makes text small

Page 28: CSE 3345 - Graphical User Interfaces

CSE 3345 28

HTML Doctype

• A set of agreed upon rules for valid HTML elements and attributes.

• You should always include a Doctype in your HTML documents! (Remember, the Doctype goes before the root element.)

• Useful for validating your HTML.

Page 29: CSE 3345 - Graphical User Interfaces

CSE 3345 29

HTML5 Doctype

• We will be using the HTML5 Doctype for all HTML documents.

• HTML5 Doctype Declaration– <!DOCTYPE HTML>

Page 30: CSE 3345 - Graphical User Interfaces

CSE 3345 30

Let’s Dive in<!DOCTYPE HTML><html><head><title>Let’s Dive in</title></head><body><div> <h1>What is HTML?</h1> <p>HTML is the root of web pages and the backbone of web user interfaces.</p> <strong>I love HTML</strong></div></body></html>

Page 31: CSE 3345 - Graphical User Interfaces

HTML Forms

• A composition of controls that include buttons, checkboxes, text input, etc. that are used to capture user input.

Page 32: CSE 3345 - Graphical User Interfaces

CSE 3345 32

Form Example

Page 33: CSE 3345 - Graphical User Interfaces

CSE 3345 33

How a form works

Facebook serverTom’s computer

Page 34: CSE 3345 - Graphical User Interfaces

Form Controls

• Types of controls:– Button– Checkbox– Radio button– Hidden Control– File Select– Text input– Menus– Others

Page 35: CSE 3345 - Graphical User Interfaces

Form controls

• Use the <input> element to create a control

• Set the value of the type attribute to the desired control

• Set the id and name attribute to use as a link between your form and the processing script.

<input type=“button” />

Page 36: CSE 3345 - Graphical User Interfaces

Buttons

1. Submit - When activated, it will submit a form for processing.

2. Reset - When activated, it will reset all controls to their initial value.

3. Push- Have no default behavior. Use these for client-side scripts.

Page 37: CSE 3345 - Graphical User Interfaces

Button example

<input type=“submit” value=“Process form”/>

<input type=“reset” value=“Reset form”/>

<input type=“button” value=“Push button”/>

Page 38: CSE 3345 - Graphical User Interfaces

CSE 3345 38

The “Log In” button is an example of a submit button. When the user presses the “LogIn” button it will process the user information and try to log the user into facebook.

Page 39: CSE 3345 - Graphical User Interfaces

Checkboxes

• On/off switches that can be toggled by the user

• A checkbox is “on” when the element’s checked attribute is true

• Several checkboxes in a form can have the same name attribute. – This is used to select multiple values for the same

property.

Page 40: CSE 3345 - Graphical User Interfaces

Checkboxes

• Multiple checkboxes that have the same name can be “on”

• Only “on” checkboxes can be successful.– Only “on” values will be sent for server processing

Page 41: CSE 3345 - Graphical User Interfaces

Checkbox Example<input type=“checkbox” name=“interests” value=“cooking”/><input type=“checkbox” name=“interests” value=“eating”/><input type=“checkbox” name=“interests” value=“coding”/>

Page 42: CSE 3345 - Graphical User Interfaces

CSE 3345 42

“Keep me logged in” is a checkbox.

Page 43: CSE 3345 - Graphical User Interfaces

Radio Button

• Similar to checkboxes except when several share the same name attribute, they are mutually exclusive.

• Browser behavior for any radio groups which don’t specify an “on” radio button is undefined.

Page 44: CSE 3345 - Graphical User Interfaces

Radio Button Example<input type=“radio” name=“gender” value=“male” /><input type=“radio” name=“gender” value=“female” />

Page 45: CSE 3345 - Graphical User Interfaces

CSE 3345 45

“Gender choice” is a radio box.

Page 46: CSE 3345 - Graphical User Interfaces

Hidden

• Allows developers to pass additional values from a form for processing in a subtle manner.

• Useful for temporary, session-based, or state data.

• Not visually rendered by browser

• Still visible when inspecting html

Page 47: CSE 3345 - Graphical User Interfaces

Hidden Example<input type="hidden" name="orderNumber" id="orderNumber" value="0024“ />

Page 48: CSE 3345 - Graphical User Interfaces

File Select

• Allows users to select files so that their contents may be submitted with the form.

• Useful for uploading local files to a server

• Use a hidden field with the name attribute set to MAX_FILE_SIZE to limit the file size that can be uploaded.– (Not really)

Page 49: CSE 3345 - Graphical User Interfaces

File Select Example<input type="hidden" name="MAX_FILE_SIZE" value="500" /><input type="file" name="uploadField" />

Page 50: CSE 3345 - Graphical User Interfaces

Text Input

• Textfield – a single line text input control

• Textarea – a multiline text input control

Page 51: CSE 3345 - Graphical User Interfaces

Textfield

• Set the input element’s type attribute to text

• Is the default value for input controls

• Designed to capture single words or phrases from a user

• Use the maxlength attribute to restrict the number of characters for a field.

Page 52: CSE 3345 - Graphical User Interfaces

Textfield Example

<input type=“text” name=“username” />

Page 53: CSE 3345 - Graphical User Interfaces

CSE 3345 53

Each of these boxes are textfield inputs and only take one piece of information each.

Page 54: CSE 3345 - Graphical User Interfaces

Textarea

• Used for large blurbs of text

• Use the <textarea> element

• Any data between the beginning and end tags will be rendered as the textarea’s default text.

Page 55: CSE 3345 - Graphical User Interfaces

Textarea

• Use the attributes row and cols to control the render size of the textarea. – Doesn’t limit character input

• Use the wrap attribute to determine how text will react when it reaches the end of a row for the textarea.– soft -forces words to wrap, but formatted text isn’t sent to

be processed. – hard – forces words to wrap and will be processed by

server as shown.– off – ignores wrapping and places text in one long line.

Page 56: CSE 3345 - Graphical User Interfaces

Textarea Example<textarea cols="20" rows="5" wrap="hard"> As you can see many times word wrapping is often the desired look for your textareas. Since it makes everything nice and easy to read and preserves line breaks. </textarea>

Page 57: CSE 3345 - Graphical User Interfaces

Menus

• Aka “drop-down-list”

• Similar to checkboxes because they allow users to select one or more values.

• Use multiple attribute with value set to yes to allow users to select multiple values with Ctrl+click

Page 58: CSE 3345 - Graphical User Interfaces

Menus

• Use the <select> element to define the menu

• Use the <option> element to specify an item in the menu.

• Use the <optgroup> element to group related options together.

Page 59: CSE 3345 - Graphical User Interfaces

Menu Example

<select id=“foreignCars”>  <optgroup label="Swedish Cars">    <option value="volvo">Volvo</option>    <option value="saab">Saab</option>  </optgroup>  <optgroup label="German Cars">    <option value="mercedes">Mercedes</option>    <option value="audi">Audi</option>  </optgroup></select>

Page 60: CSE 3345 - Graphical User Interfaces

CSE 3345 60

The controls for selecting your birthday are menu inputs.

Page 61: CSE 3345 - Graphical User Interfaces

Other Controls

• url• Password• Telephone• Etc

See w3c for more details.

Page 62: CSE 3345 - Graphical User Interfaces

CSE 3345 62

Form action attribute

• Forms rely on an action attribute to specify where to send the form data.

Page 63: CSE 3345 - Graphical User Interfaces

HTML Form action attribute

• Specifies a form processing agent (PHP, Python, Ruby, etc. script)

• Usually an HTTP URI

• Could launch an email client. Useful for debugging

<form name="myWebForm" action="mailto:[email protected]" method="post">

<input type="checkbox" /> Checkbox 1<br /> <input type="text" /> Text Field 1<br /> <input type="submit" value="SUBMIT" />

</form>

Page 64: CSE 3345 - Graphical User Interfaces

CSE 3345 64

Form method attribute

• Forms rely on a method attribute to specify how to process the form data.

Page 65: CSE 3345 - Graphical User Interfaces

HTML Form method attribute

• Specify the HTTP method to submit the form

• Two possible values:– get– post

Page 66: CSE 3345 - Graphical User Interfaces

Let’s give it a try!