Figure 1: HTTP Request Cycle
Firefox
Apache
is the most widely used server, but many others existFigure 2: HTTP Request
"GET"
: to fetch information"POST"
: to submit form data or upload files/index.html
"HTTP/1.0"
"HTTP/1.1"
"Accept: text/html"
"Accept-Language: en, fr"
"If-Modified-Since: 16-May-2005"
"Content-Length"
header tells the server how many bytes to readFigure 3: HTTP Response
Code | Name | Meaning |
---|---|---|
100 | Continue | Client should continue sending data |
200 | OK | The request has succeeded |
204 | No Content | The server has completed the request, but doesn't need to return any data |
301 | Moved Permanently | The requested resource has moved to a new permanent location |
307 | Temporary Redirect | The requested resource is temporarily at a different location |
400 | Bad Request | The request is badly formatted |
401 | Unauthorized | The request requires authentication |
404 | Not Found | The requested resource could not be found |
408 | Timeout | The server gave up waiting for the client |
500 | Internal Server Error | An error occurred in the server that prevented it fulfilling the request |
601 | Connection Timed Out | The server did not respond before the connection timed out |
<form>…</form>
element
action
attribute specifies the URL to send data tomethod
attribute specifies the type of HTTP request to send
"GET"
for simple HTML forms"POST"
for more complicated forms and for loading data<form action="myscript.cgi" method="get"></form>
<form>…</form>
tags:
<form action="myscript.cgi" method="get">
<div class="entry">
<span class="header">First Name: </span>
<input name="first_name" type="text"/>
</div>
<div class="entry">
<span class="header">Last Name:</span>
<input name="last_name" type="text"/>
</div>
</form>
select
to let users choose values from a listbutton
for basic push buttonstextarea
for large text inputinput
used for all other form fields (checkboxes, file uploads, radio buttons, single-line text input)name
attribute that can be used on the server to access the form datadisabled
attribute to disable the elementinput
elements do not generally have an end tag (all controls and data are in attributes)Example:
<select/>
elements to let users choose values from a list<option/>
elements
selected
attribute indicates which option is selectedvalue
attribute will pass a value to the serverlabel
attribute specifices a shorter labelmultiple
attribute to allow for multiple selectionsize
to set the number of visible options in the list<form action="myscript.cgi" method="get">
<select multiple="multiple" name="state" size="3">
<option value="AL">Alabama</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA" selected="selected">California</option>
<option value="CO">Colorado</option>
…
</select>
<select name="state">
<option value="AL">Alabama</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA" selected="selected">California</option>
<option value="CO">Colorado</option>
…
</select>
</form>
Example:
<button/>
elements provide a general push-button mechanismtype
attribute to set the button type:
button
is a "normal" buttonreset
is a "reset" buttonsubmit
is a "submit" button, which causes the form and all of its data to be sent to the servervalue
attribute to set the button value<form action="myscript.cgi" method="get">
<button value="clickme" name="button1" type="button"><b>Click</b> <i>me</i>!</button>
</form>
<textara/>
elements provide a general text input mechanismrows
and cols
to specify the sizereadonly
attribute to make the field read only<form action="myscript.cgi" method="get">
<textarea rows="6" cols="20" name="textinput">Enter text to be uploaded</textarea>
</form>
Example:
name
are grouped
<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>
<input type=text placeholder="(555) 555-5555">
used to provide sample text in an input field.<input type=text maxlength="10">
used to indicate the maximum length of text input<input autofocus type=text>
used to automatically focus the cursor<input type=number min=0 max=100 step=5>
used to restrict the minimum, maximum and step values
for numeric input<input type=text list=planetdata>
<datalist id=planetdata>
<option value="Earth">
<option value="Venus">
<option value="Mars">
</datalist>
used to provide a list of options within a text box<form autocomplete=off>
used to disable autocompletion on a form.document.write("<h1>"+name+"</h1>");
can write a variable text into an HTML pagevar x=1;
var x1="someText";
x="someOtherText";
are all legal JavaScript statements{}
:
var i=0;
for (i = 0; i <= 10; i++)
{
document.write("The number is "+i);
document.write("<br/>");
}
function
statement:
function displayGene(name, start, protein)
{
alert("Gene "+name+" starts at "+start+
" and translates to the sequence: "+protein);
}
<script/>
tags:
<script type="text/javascript"> document.write("Hello World!"); </script>
<head>
surrounded by <script/>
tags.src
attribute to the script
tag:
<script type="text/javascript" src="js/myFuncs.js" />
<p>This is a
<span style="color:green;border:thin blue solid;" onclick="alert('Hi!');">clickable</span>
word</p>
This is a clickable word
<html>
<body>
<form>
<script type="text/javascript">
function validate()
{
var input = document.getElementById("number");
var number = Number(input.value);
if (number < 1 || number > 10 || isNaN(number)) {
alert("Number must be between 1 and 10");
input.value = "";
return false;
}
return true;
}
</script>
Enter a number between 1 and 10:
<input type="text" id="number" name="number" onchange="validate();"/>
</form>
</body>
</html>
Tags | Attribute | Description |
---|---|---|
Window Events | ||
body | onload | Script to be run when a document loads |
body | onunload | Script to be run when a document unloads |
Form Element Events | ||
form elements | onchange | Script to be run when the element changes |
form elements | onsubmit | Script to be run when the form is submitted |
form elements | onreset | Script to be run when the form is reset |
form elements | onselect | Script to be run when the element is selected |
form elements | onblur | Script to be run when the element loses focus |
form elements | onfocus | Script to be run when the element gets focus |
Keyboard Events | ||
content elements | onkeydown | What to do when key is pressed |
content elements | onkeypress | What to do when key is pressed and released |
content elements | onkeyup | What to do when key is released |
Mouse Events | ||
content elements | onclick | What to do on a mouse click |
content elements | ondblclick | What to do on a mouse double-click |
content elements | onmousedown | What to do when mouse button is pressed |
content elements | onmousemove | What to do when mouse pointer moves |
content elements | onmouseout | What to do when mouse pointer moves out of an element |
content elements | onmouseover | What to do when mouse pointer moves over an element |
content elements | onmouseup | What to do when mouse button is released |
document
objectdocument.getElementById(), document.getElementsByName(),
document.getElementsByTagNameNS(), document.getElementsByClassName()
getElementById()
is singular. All others will return an array of elementsvar x = element.innerHTML // the HTML contains within this element
var x = element.style // the style information for this element
var x = element.className // the element's class
var x = element.attributes // the element's attributes
getElementBy
methods. This allows you to walk the HTML tree, if you need todocument.createELementNS(), document.createAttribute(),
and
element.appendChild()
provide the tools need to add to an HTML documentclass
of an
element, you could just change the className
property.<html>
<head>
<title>Class change test</title>
<link type="text/css" rel="stylesheet" href="classTest.css"/>
<script type="text/javascript" src="classTest.js" ></script>
</head>
<body>
<h1 class="header" id="header" onclick="changeClass(this);">Playing with classes</h1>
<p class="plain" onclick="changeClass(this);">Four score and seven years ago ...</p>
<p class="plain" onclick="changeClass(this);">Now we are engaged ...</p>
<p class="plain" id="final" onclick="changeClass(this);">
But, in a larger sense, we can not dedicate ...</p>
<p class="hidden" id="citation">Gettysburg Address<br/>
Abraham Lincoln<br/>
November 19, 1863</p>
</body>
</html>
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;
}
// 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";
}
}
}
Array, Boolean, Date, Number, String
Math
RegExp
decodeURI(), decodeURIComponent(), encodeURI(), encodeURIComponent(), escape(),
eval(), isFinite(), isNaN(), Number(), parseFloat(), parseInt(), String(),
and
unescape()
Window, Navigator, Screen, History,
and
Location
Document, Form, Option, Select,
and
Style
alert()
is a useful, quick debugging aid