Web Client Programming

John "Scooter" Morris

April 9, 2013

Portions Copyright © 2005-06 Python Software Foundation.

Introduction

Web Programming

The Hypertext Transfer Protocol

HTTP Request Line

Headers

Body

HTTP Response

HTTP Response Codes

Questions on HTTP?

Client Programming

HTML Forms

Creating Forms

Form Fields

Form Fields: <select>

Form Fields: <button>

Form Fields: <textarea>

Form Fields: <input/>

A Simple Form

Sequence: Search type:

Programs: FROG (version 1.1) FROG (2.0 beta) Bayes-Hart

<html>
  <body>
    <form>
      <p>Sequence: <input type="text"/>
      Search type:
      <select>
        <option>Exact match</option>
        <option>Similarity match</option>
        <option>Sub-match</option>
      </select>
      </p>
      <p>Programs: 
      <input type="radio" name="alg">
        FROG (version 1.1)
      </input>
      <input type="radio" name="alg">
        FROG (2.0 beta)
      </input>
      <input type="radio" name="alg">
        Bayes-Hart
      </input>
      </p>
      <p>
        <input type="button" value="Submit Query"/>
        <input type="button" value="Reset"/>
      </p>
    </form>
  </body>
</html> 

HTML5 Form Extensions

HTML5 Form Extensions

HTML5 Form Extensions

HTML5 Form Extensions

Questions on Forms?

Javascript

Why Javascript?

Basic syntax

Getting your script to execute

Getting your script to execute (events)

Getting your script to execute (events)

HTML Events

TagsAttributeDescription
Window Events
bodyonloadScript to be run when a document loads
bodyonunloadScript to be run when a document unloads
Form Element Events
form elementsonchangeScript to be run when the element changes
form elementsonsubmitScript to be run when the form is submitted
form elementsonresetScript to be run when the form is reset
form elementsonselectScript to be run when the element is selected
form elementsonblurScript to be run when the element loses focus
form elementsonfocusScript to be run when the element gets focus
Keyboard Events
content elementsonkeydownWhat to do when key is pressed
content elementsonkeypressWhat to do when key is pressed and released
content elementsonkeyupWhat to do when key is released
Mouse Events
content elementsonclickWhat to do on a mouse click
content elementsondblclickWhat to do on a mouse double-click
content elementsonmousedownWhat to do when mouse button is pressed
content elementsonmousemoveWhat to do when mouse pointer moves
content elementsonmouseoutWhat to do when mouse pointer moves out of an element
content elementsonmouseoverWhat to do when mouse pointer moves over an element
content elementsonmouseupWhat to do when mouse button is released
Table 2: HTML Events

Javascript and the DOM

Javascript and the DOM

Javascript and the DOM (Example CSS)

classTest.css
h1.header {
        text-align: left;
        font-family: serif;
        color: black;
}

h1.title {
        text-align: center;
        font-family: sans-serif;
        color: green;
}

p.plain {
        margin-left: 0em;
        margin-right: 0em;
        font-style: normal;
}
p.quote {
        margin-left: 5em;
        margin-right: 5em;
        font-style: italic;
}
p.hidden {
        visibility: hidden;
}
p.visible {
        visibility: visible;
        float: right;
        color: blue;
        font-style: italic;
        margin-right: 5em;
}

Javascript and the DOM (Example JS)

classTest.js
// This function will change the class of the passed element
// Note that we deal with the header specially, and also
// handle the citation depending on the class of the final paragraph
function changeClass(element) {
        // Get the current class name of the element that called us
        var class = element.className;
        // Get the ID of the element that called us
        var id = element.id;

        // Did the header call us?
        if (id == "header") {
                // Yes, switch our class
                if (class == "header") {
                        element.className = "title";
                } else if (class == "title") {
                        element.className = "header";
                }
                return;
        }
        // Make sure it's a paragraph
        if (element.tagName == "P" || element.tagName == "p") {
                // Yes, switch it
                if (class == "plain") {
                        element.className = "quote";
                        // Is it the final paragraph?
                        if (id == "final")
                                // Yes, switch the citation
                                document.getElementById("citation").className = "visible";
                } else if (class == "quote") {
                        element.className = "plain";
                        // Is it the final paragraph?
                        if (id == "final")
                                // Yes, switch the citation
                                document.getElementById("citation").className = "hidden";
                }
        }
}

Other Javascript Objects

Debugging client code

Client-side Programming

Assignment