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

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

Valid XHTML 1.0 Strict Valid CSS!

Interactive HTML user interfaces

HTML form

Document Object Model (DOM)

DOM

Global DOM objects

Recall: event handlers

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

Click me!


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!


DOM style property

function enlarge(id) {
    var element = document.getElementById(id);
    element.style.fontSize = "42pt";
}

Click me and make me big!


Buttons: <button>

<button onclick="alert('Hello!');">Click me!</button>

The DOM innerHTML property

<button id="b1" onclick="myFunction('I did it!');">Click me!</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.


Another <button> example

<button id="b1" onclick="addText();">Click me!</button>
function addText() {
    var button = document.getElementById("b1");
    button.innerHTML += " narf";
}

Text boxes: <textarea> (DOM)

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

Practice problem: Shuffle

Drop-down list: <select> (DOM), <option> (DOM)

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

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>

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>

Input fields: <input>

<input type="text" /><br />
<input type="password" size="12" />

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>

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>

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:



Practice problem: Colored text