Well House Consultants Samples Notes From Well House Consultants 1
Well House Consultants Samples Notes From Well House Consultants 1
Notes from
Well House
Consultants
These notes are written by Well House Consultants and distributed
under their Open Training Notes License. If a copy of this license is not
supplied at the end of these notes, please visit
http://www.wellho.net/net/whcotnl.html
for details.
Well House Consultants provides niche training, primarily but not exclusively in
Open Source programming languages. We offer public courses at our training centre
and private courses at your offices. We also make some of our training notes available
under our "Open Training Notes" license, such as we’re doing in this document here.
You are NOT allowed to charge (directly or indirectly) for the copying or distribu-
tion of these notes, nor are you allowed to charge for presentations making any use
of them.
If you would like us to attend a course (Java, Perl, Python, PHP, Tcl/Tk, MySQL
or Linux) presented by the author of these notes, please see our public course
schedule at
http://www.wellho.net/course/index.html
If you have a group of 4 or more trainees who require the same course at the same
time, it will cost you less to have us run a private course for you. Please visit our onsite
training page at
http://www.wellho.net/course/otc.html
which will give you details and costing information
Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Style sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
JavaScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Java Programming for the Web HTML for Web Application Authors 3
Q625
2.1 Tables
Within a page of HTML, you can specify an ordered list (<ol>) or an unordered
list (<ul>), ending with </ol> and </ul> respectively. Individual list items should
be prefixed with <li>.
To give better control over formatting than a list, you may want to arrange your
data into a table. Tables are enclosed in <table> and </table> tags; within tables,
rows are enclosed in <tr> and </tr> tags, and within each row, data elements are
enclosed in <td> and </td> tags. Many parameters can be specified to tables to
control their looks. You’ll find that tables are used for the layout of the majority of
web sites, with one table very often nested within the cell of another. A tip if you’re
trying to work out why your tables don’t display properly: set the attribute border=1
on the open table tag.
Here’s a table sample:
<html>
<head><title>Table Demo</title></head>
<body>
<h2 align=center>A Sample Table</h2>
<table border=1>
<tr><td>January</td>
<td>31</td>
<td>Winter</td>
</tr><tr><td>February</td>
<td>28 or 29</td>
<td>Winter</td>
</tr><tr><td>March</td>
<td>31</td>
<td>Winter</td>
</tr><tr><td>April</td>
<td>30</td>
<td>Spring</td>
</tr></table>
<hr>
© Well House Consultants,
2004<br>
01225 708225
</body>
</html>
Although the raw HTML source of a table is often very hard to follow, it’s surpris-
ingly easy to generate within a program using nested loops. We didn’t write the above
code directly, we used the following piece of PHP:
<html>
<head><title>Table Demo</title></head>
<body>
<h2 align=center>A Sample Table</h2>
<table border=1>
<?php
$info = array(
array("January",31,"Winter"),
array("February","28 or 29","Winter"),
array("March",31,"Winter"),
array("April",30,"Spring"));
foreach ($info as $month) {
print "<tr>";
foreach ($month as $cell) {
print "<td>$cell</td>\n";
}
print "</tr>";
}
?>
</table>
<hr>
© Well House Consultants, <?php print(date("Y")); ?><br>
01225 708225
</body>
</html>
2.2 Frames
On many sites, the browser window is divided into a series of frames. In this case,
you'll have multiple HTML documents. The window as a whole will be defined in one
document (a frameset), with each of the resulting frames being defined in its own
piece of HTML. Documents called up can then replace all the frames, or one frame,
or even open a new browser window.
Frames are useful tools on web sites where you wish to provide a control pane
that’s unchanging, and a data pane in which results are presented, but they do add to
the design and development complexity and it’s often better to use tables and refresh
the whole page as you navigate a site.
There are also issues with the titling of framed pages which make them hard to
bookmark sensibly, and with the printing of pages. It’s very easy to provide a page that
won’t print out if you use frames, and that’s why so many web sites have a "printer
friendly version" option.
2.3 Forms
Forms are a vital part of any web site that includes executable content as they’re
the mechanism that allows user data entry. With a form, you define a set of user-enter-
able boxes between a <form> and </form> tag. Within the <form> tag an action
attribute gives the URL to be called when the user indicates that the form has been
completed, and a method attribute may be specified too.
Element types within a form
There's much more you might want to do, and forms can have a range of different
elements. There are basically a number of classes of elements, but within each of
Java Programming for the Web HTML for Web Application Authors 5
Q625
them a number of attributes can be applied to tailor how they look and respond.
Here’s a sample piece of HTML that includes most of the form elements:
<HTML>
<head><title>Form Element Demo</title></head>
<BODY BGCOLOR=white text=black link=blue>
<Form method=post action="/cgi-bin/envlist.pl">
<H2>Different form elements</H2>
This calls a script that lists out all fields entered, and the whole
environment<P>
<HR><!-- ################################### -->
<H4>Type = Text</H4>
default text <INPUT type=text name=a_text>
<BR>
Another text <INPUT type=text maxlength=5 size=8
value="abc" name=a_t2>
<BR>
<HR><!-- ################################### -->
<H4>Type = radio</H4>
Select a radio button from:<BR>
<INPUT type=radio name=b_set value=Orange>
Orange Juice<BR>
<INPUT type=radio name=b_set value=Lemon CHECKED>
Lemonade<BR>
<INPUT type=radio name=b_set value=Lime>
Rose's Lime Cordial<BR>
<HR>
<H4>Type = hidden</H4>
Nothing here!
<INPUT type=hidden name=ehem value="WHC_1040198606_450">
<HR>
<!-- ################################### -->
<H4>Type = file</H4>
Looking for a file name
<INPUT type=file name=filer>
<HR>
<!-- ################################### -->
<H4>Type = checkbox</H4>
Looking for a series of answers<BR>
<INPUT type=checkbox name=hot> Is it hot?<BR>
<INPUT type=checkbox name=sunny value="sun-on"> Is it sunny?<BR>
<INPUT type=checkbox name=daytime CHECKED>
Is it daytime?<BR>
<HR>
Java Programming for the Web HTML for Web Application Authors 7
Q625
<HR>
<!-- ################################### -->
<H4>Selects</H4>
Choose ONE of these:
<SELECT name=lsel>
<OPTION>North
<Option value=south>South
<Option SELECTED value=East>East
<Option value=W>West
</SELECT><P>
Choose several of these:
<SELECT name=lset size=3 multiple>
<OPTION selected>Swimming
<Option value=Skiing>Skiing
<Option SELECTED value="Scuba diving">Scuba
<Option value=Snorkelling>Snorkelling
<Option>Sleeping
</SELECT><P>
<HR>
Because it can be used to display the contents of any form, we've pointed this set
of form examples at the environment listing script from the previous section. Here's
an example of a response from a completed form:
Java Programming for the Web HTML for Web Application Authors 9
Q625
#!/usr/bin/perl
if ($ENV{"REQUEST_METHOD"} eq "POST") {
read (STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{"QUERY_STRING"};
}
@userdata = split (/&/,$buffer);
foreach (@userdata) {
($field,$value) = /(.*)=(.*)/;
$value=~ tr/+/ /;
$value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$input{$field} .= "\n" if ($input{$field});
$input{$field} .= $value;
}
# input fields
print "</TABLE>";
# environment variables
#################################################################
sub web {
$_ = $_[0];
s/&/&/g;
s/</</g;
s/>/>/g;
s/\n\r/\n/g; # dos to standard
s/\r/\n/g; # mac to standard
s/\n{2,}/<P>/g;
s/\n/<BR>/g;
$_;
}
Java Programming for the Web HTML for Web Application Authors 11
Q625
Our web site actually goes somewhat further. By changing the style sheet file for
individual users, we can let each visitor to our site choose their own look and feel
from a set of four alternatives we have provided. Not only does this make it easier for
people to adjust our site to suit their needs, but it also helps fulfil our obligations
under the UK’s disability discrimination act.
2.6 JavaScript
You can also embed code on JavaScript in a web page, and this gives an element
of local interaction to the page if you wish. For example, you could program a select
box to automatically submit if it’s changed.
The code to define the selection element of a form (an example from our web site):
The JavaScript is defined within the page head, carefully written in an HTML
comment tag so that users of browsers who don’t understand JavaScript don’t see the
sources!
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
function leap(where) {where.submit()}
//-->
</script>
Java Programming for the Web HTML for Web Application Authors 13
Q625
Exercise
License
These notes are distributed under the Well House Consultants
Open Training Notes License. Basically, if you distribute it and use it
for free, we’ll let you have it for free. If you charge for its distribution of
use, we’ll charge.
Please send any amendments and corrections to these notes to the Copyright
holder - under the spirit of the Open Distribution license, we will incorporate suit-
able changes into future releases for the use of the community.
If you are charged for this material, or for presentation of a course (Other than by
Well House Consultants) using this material, please let us know. It is a violation of
the license under which this notes are distributed for such a charge to be made,
except by the Copyright Holder.
If you would like Well House Consultants to use this material to present a training
course for your organisation, or if you wish to attend a public course is one is avail-
able, please contact us or see our web site - http://www.wellho.net - for further
details.
Change log
Original Version, Well House Consultants, 2004
License Ends.