HTML User Interface Controls

CSE 190 M (Web Programming), Spring 2008

University of Washington

Reading: Chapter 3 section 3.1

Except where otherwise noted, the contents of this presentation are © Copyright 2008 Marty Stepp and Jessica Miller and are licensed under the Creative Commons Attribution 2.5 License.

Valid XHTML 1.0 Strict Valid CSS!

Interactive HTML user interfaces

HTML form

Buttons: <button>

the most common clickable UI widget (inline)

<button>Click me!</button>

Radio buttons: <input>

sets of mutually exclusive choices (inline)

<input type="radio" name="creditcards" /> Visa
<input type="radio" name="creditcards" /> MasterCard
<input type="radio" name="creditcards" checked="checked" /> American Express
Visa MasterCard American Express

Text labels: <label>

<label><input type="radio" name="creditcards" /> Visa</label>
<label><input type="radio" name="creditcards" /> MasterCard</label>
<label><input type="radio" name="creditcards" /> American Express</label>

Checkboxes: <input>

an on/off toggle (inline)

<label><input type="checkbox" /> Lettuce</label>
<label><input type="checkbox" checked="checked" /> Tomato</label>
<label><input type="checkbox" /> Pickles</label>

Text fields: <input>

<input type="text" size="12" maxlength="8" /> NetID<br />
<input type="password" size="12" /> Password
NetID
Password

Text boxes: <textarea>

a multi-line text input area (inline)

<textarea rows="4" cols="20">
Type your comments here.
</textarea>

Drop-down list: <select>, <option>

menus of choices that collapse and expand (inline)

<select>
	<option>Jerry</option>
	<option>George</option>
	<option>Kramer</option>
	<option>Elaine</option>
</select>

Using <select> for lists

<select size="3" multiple="multiple">
	<option>Jerry</option>
	<option>George</option>
	<option>Kramer</option>
	<option>Elaine</option>
	<option selected="selected">Newman</option>
	<option>Susan</option>
</select>

Option groups: <optgroup>

<select>
	<optgroup label="Major Characters">
		<option>Jerry</option>
		<option>George</option>
		<option>Kramer</option>
		<option>Elaine</option>
	</optgroup>
	<optgroup label="Minor Characters">
		<option>Newman</option>
		<option>Susan</option>
	</optgroup>
</select>

Grouping input: <fieldset>, <legend>

groups of input fields with optional caption (block)

<fieldset>
	<legend>Credit cards:</legend>
	<label><input type="radio" name="creditcards" /> Visa</label>
	<label><input type="radio" name="creditcards" /> MasterCard</label>
	<label><input type="radio" name="creditcards" /> American Express</label>
</fieldset>
Credit cards:

Common UI control errors

Styling UI controls

element[attribute="value"] {
	property : value;
	property : value;
	...
	property : value;
}
input[type="text"] {
	background-color: yellow;
	font-style: bold;
}

Styling Text Boxes

<textarea rows="3" cols="40"></textarea>
body { height: 100%; }
textarea {
	position: absolute;
	width: 50%;
	height: 15%;
}

Making UI controls interactive

(using a bit of JavaScript)

What is JavaScript?

Creating an interactive UI

Inserting JavaScript in HTML

Linking to a JavaScript file (example)

<script src="filename" type="text/javascript"></script>
<script src="example.js" type="text/javascript"></script>

A basic JavaScript function

function name() {
	statement ;
	statement ;
	...
	statement ;
}

The alert box

alert("message");
alert("IE6 detected.  Suck-mode enabled.");

alert


Function example

function myFunction() {
	alert("Hello!");
	alert("How are you?");
}

Event handlers

<button onclick="myFunction();">Click me!</button>

Another event handler

<select onchange="myFunction();">
	<option>Jerry</option>
	<option>George</option>
	<option>Kramer</option>
	<option>Elaine</option>
</select>