CSIT128 All Slides
CSIT128 All Slides
CSIT128 All Slides
HTML
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
HTML
Objectives:
● use HTML tags to format text, add graphics, create links, display
tables, lists, etc.
2
HTML
3
The first HTML document
<html>
<head>
<title>Hi</title>
</head>
<body>
Hello World!
</body>
</html>
4
The first HTML document
<html>
<head>
<title>Hi</title>
</head>
<body>
Hello World!
</body>
</html>
5
HTML document structure
<html>
● A HTML document starts with
<head> <html> and ends with </html>
</html>
6
HTML tags
<html>
<head>
tag
<title>Hi</title>
</head>
<body>
Hello World!
</body>
</html>
7
HTML tags
tags are NOT case sensitive
<html>
<head>
tag
<title>Hi</title>
</head>
most tag goes in pair
<body>
<tagname>content</tagname>
Hello World!
</body>
start tag end tag
</html>
8
HTML tags
HTML documents are made up by HTML elements.
The HTML element is everything from the start tag to
<html>
the end tag.
<head>
<title>Hi</title>
</body>
9
Self-closing tag
<tagname></tagname>
● Example:
10
Tag attributes
11
Heading tags
<body>
<h1>Heading 1</h1>
Heading tags: <h1>, <h2>,..., <h6>
<h2>Heading 2</h2>
<h1> the most important heading
<h3>Heading 3</h3>
<h6> the least important heading
<h6>Heading 6</h6>
Normal text...
</body>
12
Unordered List
My timetable:
<ul>
</ul>
My timetable:
13
Unordered List Unordered List
My timetable:
List Item
<ul>
</ul>
My timetable:
14
Ordered List
My timetable:
<ol>
</ol>
My timetable:
15
Ordered List Ordered List
My timetable:
List Item
<ol>
</ol>
My timetable:
16
Description List
My timetable:
<dl>
<dt>MATH222</dt>
<dt>CSCI204</dt> My timetable:
CSCI204
<dt>ISIT206</dt> Tue 9:30-11:30 lab
<dt>CSCI204</dt> My timetable:
CSCI204
<dt>ISIT206</dt> Tue 9:30-11:30 lab
<ins>inserted text</ins>
19
Formatting text
<ins>My timetable:</ins>
<ul>
</ul>
My timetable:
20
Formatting text
<h1>HTML <small>Small</small> Formatting</h1>
21
Formatting text
Changing font
<font size="1">This is the smallest size</font>
22
Formatting text
<body>
Some math
x<sub>1</sub><sup>n</sup> +
x<sub>2</sub><sup>n</sup> =
y<sub>1</sub><sup>n</sup> +
y<sub>2</sub><sup>n</sup>
</body>
23
Table border attribute
<table border="1">
<tr>
<th>Username</th>
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>jsmith</td>
<td>John</td>
<td>Smith</td>
</tr>
<tr>
<td>mlee</td>
<td>Mary</td>
<td>Lee</td>
</tr>
</table>
Turn off the border:
border="0"
24
Table
<table border="1">
Table Row
<tr>
<th>Username</th>
<th>First name</th> row 1
<th>Last name</th>
</tr>
<tr>
<td>jsmith</td>
<td>John</td> row 2
<td>Smith</td>
</tr>
<tr>
<td>mlee</td>
<td>Mary</td> row 3
<td>Lee</td>
</tr>
</table>
25
Table
<table border="1">
<tr>
<th>Username</th> Table Header
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>jsmith</td> Table Data
<td>John</td>
<td>Smith</td>
</tr>
<tr>
<td>mlee</td>
<td>Mary</td>
<td>Lee</td>
</tr>
</table>
26
Table
<table border="1">
<tr>
<td>jsmith</td> Sometime we do not need
<td>John</td> table header
<td>Smith</td>
</tr>
<tr>
<td>mlee</td> Table Data
<td>Mary</td>
<td>Lee</td>
</tr>
</table>
27
Table
<table border="1" width="50%">
<caption>User information</caption>
<tr>
<th width="20%">Username</th>
<th width="40%">First name</th>
<th width="40%">Last name</th>
</tr>
<tr>
<td align="center">jsmith</td>
<td align="right">John</td>
<td align="right">Smith</td>
</tr>
<tr>
<td align="center">mlee</td>
<td align="right">Mary</td>
<td align="right">Lee</td>
</tr>
</table>
28
Table
<table border="1" width="50%">
<caption>User information</caption>
<tr>
<th width="20%">Username</th>
<th width="40%">First name</th>
<th width="40%">Last name</th>
Table caption
</tr>
<tr>
<td align="center">jsmith</td>
<td align="right">John</td>
<td align="right">Smith</td>
</tr>
<tr>
<td align="center">mlee</td>
<td align="right">Mary</td>
<td align="right">Lee</td>
</tr>
</table>
29
Table Table width
within the page
<table border="1" width="50%">
<caption>User information</caption>
<tr> Column width
<th width="20%">Username</th> within the table
<th width="40%">First name</th>
<th width="40%">Last name</th>
</tr>
<tr>
<td align="center">jsmith</td>
<td align="right">John</td>
<td align="right">Smith</td>
</tr>
<tr>
<td align="center">mlee</td>
<td align="right">Mary</td>
<td align="right">Lee</td>
</tr>
</table>
30
Table
<table border="1">
<caption>User information</caption>
<tr> Column width
<th width="150px">Username</th> using pixels
<th width="200px">First name</th>
<th width="200px">Last name</th>
</tr>
<tr>
<td align="center">jsmith</td>
<td align="right">John</td>
<td align="right">Smith</td>
</tr>
<tr>
<td align="center">mlee</td>
<td align="right">Mary</td>
<td align="right">Lee</td>
</tr>
</table>
31
Table
<table border="1" width="50%">
<caption>User information</caption>
<tr>
<th width="20%">Username</th>
<th width="40%">First name</th>
<th width="40%">Last name</th>
</tr> Horizontal
<tr> alignment
<td align="center">jsmith</td>
<td align="right">John</td>
<td align="right">Smith</td>
</tr>
<tr>
<td align="center">mlee</td>
<td align="right">Mary</td>
<td align="right">Lee</td>
</tr>
</table>
32
Table
<table width="50%" border="1">
<tr>
<td valign="middle">jsmith</td>
<td>
John Smith <br />
DOB: 23/01/2000 <br />
Course code: 875 Vertical
</td> alignment
</tr>
<tr>
<td valign="middle">mlee</td>
<td>
Mary Lee <br />
DOB: 15/04/2001 <br />
Course code: 741
</td>
</tr>
</table>
33
Table
<table width="50%" border="1">
<tr>
<td valign="top">jsmith</td>
<td>
John Smith <br />
DOB: 23/01/2000 <br />
Course code: 875 Vertical
</td> alignment
</tr>
<tr>
<td valign="top">mlee</td>
<td>
Mary Lee <br />
DOB: 15/04/2001 <br />
Course code: 741
</td>
</tr>
</table>
34
Table
<table width="50%" border="1">
<tr>
<td valign="bottom">jsmith</td>
<td>
John Smith <br />
DOB: 23/01/2000 <br />
Course code: 875 Vertical
</td> alignment
</tr>
<tr>
<td valign="bottom">mlee</td>
<td>
Mary Lee <br />
DOB: 15/04/2001 <br />
Course code: 741
</td>
</tr>
</table>
35
Table Column span
<table border="1" width="40%">
<tr>
<td colspan="2">STUDENT DETAILS</td>
</tr>
<tr>
<td width="30%">STUDENT NAME</td>
<td>John Lee</td>
</tr>
<tr>
<td>STUDENT NUMBER</td>
<td>1234567</td>
</tr>
<tr>
<td>UOW EMAIL</td>
<td>jlee@uowmail.edu.au</td>
</tr>
</table>
36
Table Row span
<table border="1" width="50%">
<tr>
<td></td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
</tr>
<tr>
<td>8:30-9:30</td>
<td rowspan="2">MATH 321 lecture</td>
<td>INFO 104 lecture</td>
<td>CS 222 lecture</td>
</tr>
<tr>
<td>9:30-10:30</td>
<td>CS 222 Lab</td>
<td rowspan="2">MATH 321 tutorial</td>
</tr>
<tr>
<td>10:30-11:30</td>
<td>CS 222 lecture</td>
<td>INFO 104 tutorial</td>
</tr>
</table> 37
Paragraph tag <p>
<p>This is a paragraph</p>
Extra spaces and lines will NOT
<p>Another be displayed in paragraph
paragraph</p>
<p>yet another
paragraph</p>
38
Line break <br />
<p>This is a paragraph</p>
<br /> tag defines a line break
<p>Another <br />
<br /> is an empty element
paragraph</p> (i.e. it is a tag with no content),
it combines the start and end
<p>yet another <br /> tags together
<br />
paragraph</p>
39
Horizontal line <hr />
<p>This is a paragraph</p>
similarly, we have the
<p>Another <br /> horizontal line tag <hr />
with no content
paragraph</p>
<hr />
<br />
paragraph</p>
40
Non-breaking space
<p>This is a
use for non-breaking space
paragraph</p>
paragraph</p>
<hr />
<br />
paragraph</p>
41
Character entity
● Some characters are reserved in HTML.
o ° Degree
© © Copyright
42
Character entity
<body>
</body>
43
Block quotations <blockquote>
<p>normal paragraph</p>
<blockquote>
</blockquote>
44
Preformatted text <pre>
<pre>
pre element is shown in monospace
Mary
it preserves the character and line spacing
had a
little
lamb
</pre>
45
Computer code
<pre>
<code>
a = 0;
b = 3;
c = 2;
sum = a + b + c;
</code>
</pre>
what would happen if we use <code> … </code>
without <pre> ?
46
If you want to include special characters such as
Computer code < > & " '
within pre tags, they should be substituted by
character entities so that they are not subject to
<pre>
special interpretation by the browser.
<code>
#include <iostream>
void main( ) {
cout << "Hello World!" << endl;
}
</code>
</pre>
#include <iostream>
void main( ) {
cout << "Hello World!" << endl;
}
47
Image
<img src="uow-logo.png" height="300" width="200"
Attribute Description
height optional.
width Specifies height, width for image in pixels, or in percentage
48
Image alt
<img src="uow-logo.png" height="300" width="200"
49
Image src
The URL of an image can be
● an absolute URL points to another website
● or a relative URL points to an image file within a website
Absolute URL
src="http://www.mycom.au/staff.png"
Relative URL
src="images/logo/uow-logo.png"
src="/../f1/bird.png"
50
Link
<a href="http://www.uow.edu.au" target="_blank">Visit UOW</a>
</a>
51
Link
<a href="http://www.uow.edu.au" target="_blank">Visit UOW</a>
target description
52
Link
<a href="contact.html">Contact us</a>
href="contact.html"
href="assignment/a1.html"
href="../handout/note5.html"
53
Link
<a href="http://www.uow.edu.au" target="_blank">
</a>
Within the link tag <a href...> </a>, we can put any text or image.
54
Link - target within document
Within the html document we can use the attribute id to mark a specific location
<h3 id="Proofs">Proofs</h3>
…
<h3 id="Notes">Notes</h3>
…
<h3 id="References">References</h3>
…
<h3 id="Proofs">Proofs</h3>
…
The id value must be unique and must contain at least one character.
The id value must not contain any space characters.
56
Link - target within document
We can create a link to a specific location within a html page
For example:
<a href="https://en.wikipedia.org/wiki/Euler%27s_theorem#Proofs">
Proof of the Euler theorem</a>
57
index.html
● It stops people from knowing the content and structure of your website
58
Comments
<body>
<!-- this is
a long comment
-->
</body>
59
XHTML
● XHTML stands for EXtensible HyperText Markup Language
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
DOCTYPE and xmlns are mandatory
</body>
</html>
60
XHTML
61
XHTML
<HEAD>
<TITLE>Web Technologies</TITLE>
<HEAD>
63
XHTML
64
XHTML
65
XHTML
66
HTML5
67
References
● http://www.w3schools.com/html
● http://developer.mozilla.org/en-US/docs/Web/HTML
68
Introduction to Web Technology
CSS
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
CSS
Objectives:
2
Cascading Style Sheets
● Inline
● Document
● External
3
Inline CSS
<body style="background-color:lightgrey;">
4
Inline CSS
</p>
5
this is called a CSS property
Inline CSS
</p>
6
Inline CSS
</p>
7
Inline CSS
</p>
property:value
● We can specify more than one CSS property, separated by a semicolon (;)
9
Document CSS
<html>
<head>
<title>W3</title>
<style>
body {background-color:lightgrey;}
h1 {color:blue;}
p {border:1px solid black; padding:10px;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
</body>
</html>
10
External CSS
<html>
<head>
<title>W3</title>
<link rel="stylesheet" href="path/to/mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
</body>
</html>
mystyle.css
body {background-color:lightgrey;}
h1 {color:blue;}
p {border:1px solid black; padding:10px;}
11
Levels of CSS
12
CSS convention mystyle.css
body {background-color:lightgrey;}
This is a valid CSS h1 {color:blue;}
p {border:1px solid black; padding:10px;}
body {
background-color:lightgrey;
}
h1 {
color:blue;
}
p {
border:1px solid black; each property on
padding:10px; a separate line
}
13
Simple selector
14
Class selector
<h1 class="userInfo">This is a heading 1</h1>
<p class="userInfo">This is a paragraph 1</p>
<h2 class="userInfo">This is a heading 2</h2>
<p class="userInfo">This is a paragraph 2</p>
15
Class selector
<h1 class="userInfo">This is a heading 1</h1>
<p class="userInfo">This is a paragraph 1</p>
<h2 class="userInfo">This is a heading 2</h2>
<p class="userInfo">This is a paragraph 2</p>
16
Id selector
<h1 id="userHeading">This is a heading 1</h1>
<p id="userDetails">This is a paragraph 1</p>
17
Descendant-Ancestor
18
Descendant-Ancestor
Example:
What are the descendants
of this element div ? <div>
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
19
Child-Parent
<E>
…
<F>
…
</E>
20
Child-Parent
Example:
What are the children
of this element div ? <div>
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
21
Contextual Selector
22
Contextual Selector
Example: div i {
color:red;
<div> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
23
Contextual Selector
24
Contextual Selector
Example: div.userInfo i {
color:red;
<div class="userInfo"> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div class="bankInfo">
This is the final <i>italic</i>.
</div>
</div>
25
Contextual Selector
26
Contextual Selector
Example: div.bankInfo i {
color:red;
<div class="userInfo"> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div class="bankInfo">
This is the final <i>italic</i>.
</div>
</div>
27
Contextual Selector
28
Pseudo class selector
29
List properties ol {
list-style-type:decimal;
<ol> }
<li>First level item 1
<ol> ol ol {
<li>Second level item 1.1</li> list-style-type:upper-roman;
<li>Second level item 1.2</li> }
</ol>
</li>
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
31
span
span.specialText {
color:red;
font-family:Ariel;
font-size:150%;
}
32
div
<div class="userInfo">
<p>This section displays user information.</p>
</div>
<div class="bankInfo">
<p>This section display bank information.</p>
</div>
div.userInfo {
border:1px solid black;
padding:10px;
}
div.bankInfo {
background-color:lightgrey;
} 33
Comments in CSS
A comment starts with /* and ends with */
p {
border:1px solid black;
color:blue;
}
/* This is
a multi-line
comment */
34
References
● http://www.w3schools.com/css
● https://en.wikipedia.org/wiki/Cascading_Style_Sheets
● https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
35
Introduction to Web Technology
Basics of JavaScript
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
JavaScript
Objectives:
2
My First JavaScript
<button onClick="alert('Hi');">
Click me
</button>
<button onClick="alert(1+1);">
Click me
</button>
3
My First JavaScript
<button onClick="console.log('Hi');">
Click me
</button>
<button onClick="console.log(2+2);">
Click me
</button>
4
My First JavaScript
5
My First JavaScript
<button onClick="sayHi();">
Click me
</button>
<script>
function sayHi(){
alert("Hi");
}
</script>
6
Where to include JavaScript
Common practice:
● In the head
● At the end of body
<script>
function sayHi(){
alert("Hi");
}
</script>
7
Where to include JavaScript
In the head
<head>
<title>JavaScript Example</title>
<script>
function sayHi(){
alert("Hi");
}
</script>
</head>
8
Where to include JavaScript
...
<script>
function sayHi(){
alert("Hi");
}
</script>
</body>
</html>
9
External JavaScript
<script>
function sayHi(){
alert("Hi");
}
</script>
10
Basic JavaScript syntax
function silly(){
alert('Hi');
console.log(2+2);
}
11
Basic JavaScript syntax
JavaScript Comments
Code after double slashes // or between /* and */ is treated as a comment.
Comments are ignored, and will not be executed.
/*
this function does a few silly things
*/
function silly(){
// display an alert box
alert('Hi');
13
Basic JavaScript syntax
underscore:
student_name, student_id, first_name, last_name
camel case:
studentName, studentId, firstName, lastName
14
Basic JavaScript syntax
15
Basic JavaScript syntax
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
16
Basic JavaScript syntax
17
Basic JavaScript syntax
18
Basic JavaScript syntax
var x;
19
Basic JavaScript syntax
20
Basic JavaScript syntax
JavaScript evaluates expressions from left to right
var x;
var x = 5;
var positive = (x > 0); //true
if(positive){
alert("x is positive");
} 22
Basic JavaScript syntax
Comparison and Logical Operators
== equal to
!= not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to
23
Basic JavaScript syntax
var x = 5;
var y = 6;
if(x == y){
alert("x and y are equal");
}else{
alert("x and y NOT are equal");
}
var x = 5;
var y = 6;
if(x != y){
alert("x and y are not equal");
}else{
alert("x and y are equal");
24
}
Basic JavaScript syntax
var mark = 75;
25
Useful tags for dynamic content:
26
Change content by JavaScript
○ Step 1: give the HTML element that we want to change an ID
for image:
e.src = "the-new-image-src"; 27
Cat & Dog 1
The web page displays 2 buttons: “Cat” and “Dog”.
28
Cat & Dog 1
<button onClick="cat()">Cat</button>
<button onClick="dog()">Dog</button>
<br /> <br />
<span id="display"></span>
29
Cat & Dog 1
function dog(){
// get the span element
30
Cat & Dog 1
function dog(){
// get the span element
var displaySpan = document.getElementById("display");
<span id="display"></span>
31
Cat & Dog 1
function dog(){
// get the span element
var displaySpan = document.getElementById("display");
32
Cat & Dog 1
function cat(){
// get the span element
var displaySpan = document.getElementById("display");
33
Change content by JavaScript
○ Step 1: give the HTML element that we want to change an ID
for image:
e.src = "the-new-image-src"; 34
Cat & Dog 2
The web page displays 2 buttons: “Cat” and “Dog”, and a text
field.
35
Cat & Dog 2
<button onClick="cat()">Cat</button>
<button onClick="dog()">Dog</button>
<br /> <br />
<input type="text" id="display" />
36
Cat & Dog 2
function cat(){
// get the text field element
37
Cat & Dog 2
function cat(){
// get the text field element
var displayField = document.getElementById("display");
for image:
e.src = "the-new-image-src"; 40
Cat & Dog 3
The web page displays 2 buttons: “Cat” and “Dog”.
41
Cat & Dog 3
<button onClick="cat()">Cat</button>
<button onClick="dog()">Dog</button>
<br /> <br />
<img id="display" />
42
(empty image: no src)
Cat & Dog 3
function cat(){
// get the image element
43
Cat & Dog 3
function cat(){
// get the image element
var image = document.getElementById("display");
44
Cat & Dog 3
function dog(){
// get the image element
var image = document.getElementById("display");
45
Using variables to save state information
46
Cat & Dog 4
The web page displays 2 images: “Cat” and “Dog”, and 2
click counters.
If the user clicks the “Cat” image, then the click counter for cat
is increased.
If the user clicks the “Dog” image, then the click counter for
dog is increased.
47
Cat & Dog 4
<img src="dog.png" onClick="dog()" />
<img src="cat.png" onClick="cat()" />
<br /> <br />
Dog click count: <span id="dogDisplay">0</span>
<br /> <br />
Cat click count: <span id="catDisplay">0</span>
48
Cat & Dog 4
// variable to save the number of dog clicks
var dogClick = 0;
// variable to save the number of cat clicks
var catClick = 0;
49
Cat & Dog 4
// variable to save the number of dog clicks
var dogClick = 0;
function dog(){
// increase the number of dog clicks by 1
50
Cat & Dog 4
// variable to save the number of dog clicks
var dogClick = 0;
function dog(){
// increase the number of dog clicks by 1
dogClick = dogClick + 1;
<span id="dogDisplay">0</span>
51
Cat & Dog 5
The web page displays 2 images: “Dog” on the left, “Cat” on
the right, and a button “Switch”.
If the user clicks the “Switch” button, then the two images
switch their places.
52
Cat & Dog 5
<img id="left" src="dog.png" />
<button onClick="switchImage()">
Switch
</button>
<img id="right" src="cat.png" />
53
Cat & Dog 5
// variable to save the position of dog and cat images
// two values: "dog-cat" or "cat-dog"
// original position is "dog-cat"
var position = "dog-cat";
54
Cat & Dog 5
var position = "dog-cat";
function switchImage(){
// check what is the current position, then switch it
// change position variable
// change the images
}
55
Cat & Dog 5
if(position == "dog-cat"){
// change position variable
position = "cat-dog";
56
Current position is dog-cat
Cat & Dog 5
else{
// change position variable
position = "dog-cat";
57
Current position is cat-dog
Cat & Dog 6
The web page displays a “Dog” picture.
If the user clicks the “Dog” picture, then it turns into a “Cat”
picture.
If the user clicks the “Cat” picture, then it turns back to the
“Dog” picture.
58
Cat & Dog 6
59
Cat & Dog 6
60
Cat & Dog 6
var animal = "dog";
function changeImage(){
// check what is the current animal, then change it
// change animal variable
// change the image
}
61
Cat & Dog 6
if(animal == "dog"){
// change animal variable
animal = "cat";
62
Current animal is dog
Cat & Dog 6
else{
// change animal variable
animal = "dog";
63
Current animal is cat
String
var text = "One Fish, Two Fish, Red Fish, Blue Fish";
var text = "One Fish, Two Fish, Red Fish, Blue Fish";
65
Date
66
Date
67
Date
//using YYYY-MM-DDTHH:MI:SS
var d = new Date("2000-01-30T10:00:00");
alert(d);
68
Date
69
Date
70
Date
71
Date
72
Date
73
References
● http://www.w3schools.com/js
● http://developer.mozilla.org/en-US/docs/Web/JavaScript
74
Introduction to Web Technology
Web Form
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
Web form
Objectives:
2
Form
● HTML forms are used to collect user input.
3
Form
● When user clicks a submit button, user input will be sent to the server to
process
● The front-end form elements must match up with the server back-end
program’s parameters.
4
Example: Whosville’s library book search
5
Example: Whosville’s library book search
6
Example: Whosville’s library book search
When the form is submitted, we can see the following appears in the URL:
http://library.whosville/bsearch?author=tonien&year=2000&sub=cs&sub=phy
The front-end form elements must match up with the server back-end
program’s parameters:
● Use the attribute name to specify the back-end’s parameter
8
Example: Whosville’s library book search
The front-end form elements must match up with the server back-end
program’s parameters:
● Use the attribute value to specify the data sent back to the back-end
9
Example: Whosville’s library book search
The front-end form elements must match up with the server back-end
program’s parameters:
● Sometimes the data sent back to the back-end is different from the data
10
displayed to the user.
Class discussion
http://www.ebay.com/
http://www.amazon.com.au
11
Form - type text
12
Form - type password
Username:<br />
<input type="text" name="username" size="30"/><br />
Password:<br />
<input type="password" name="password" size="30"/><br />
13
Form - type checkbox
This is the value that sent to server
Choose journals to subscribe:<br />
14
Form - type checkbox
15
Form - type radio
This is the value that sent to server
16
Form - type radio
17
Form - select This is the value that sent to server
<select name="day">
<option value="mon">Monday</option>
<option value="tue">Tuesday</option>
<option value="wed">Wednesday</option>
<option value="thu">Thursday</option>
<option value="fri">Friday</option>
</select>
18
Form - select
<select name="day">
<option value="mon">Monday</option>
<option value="tue">Tuesday</option>
<option value="wed">Wednesday</option>
<option value="thu">Thursday</option>
<option value="fri" selected="selected">Friday</option>
</select>
19
Form - select multiple
20
Form - textarea
21
Form - submit this is the program in the server that processes the form
</form>
22
Form method
<form action="handle_login" method="post">
method="get" method="post"
Visibility Data is visible in the URL Data is not displayed in the URL
Security get is less secure compared to post because data sent in part of
the URL.
Never use get when sending passwords or other sensitive
information.
23
Form method
<form action="handle_login" method="post">
method="get" method="post"
24
Form - reset
</form>
25
Form
<form ...>
First name:<br />
<input type="text" name="firstname" size="30"/><br />
Last name:<br />
<input type="text" name="lastname" size="30"/><br />
● http://www.w3schools.com/html
● http://www.w3schools.com/htmL/html_forms.asp
● http://www.w3.org/TR/html5/forms.html
27
Introduction to Web Technology
1
Objectives:
2
REVIEW: Change content by JavaScript
○ Step 1: give the HTML element that we want to change an ID
for image:
e.src = "the-new-image-src"; 3
Useful tags for dynamic content:
4
Say Hi 1
The web page displays 2 text fields: first name and last
name, and a button "Say Hi". If the user enters John in the
first name text field and Smith in the last name text field, and
clicks the "Say Hi" button, then a greeting message is
displayed on the page: "Hi John Smith!".
5
Say Hi 1
First name: <input type="text" id="firstname" /> <br />
Last name: <input type="text" id="lastname" /> <br />
<button onClick="sayHi()">Say Hi</button> <br />
<span id="greeting"></span>
6
Say Hi 1
function sayHi(){
// get the first name
7
Say Hi 1
// get the first name
var firstnameInput = document.getElementById("firstname");
var firstname = firstnameInput.value;
8
Say Hi 1
// get the last name
var lastnameInput = document.getElementById("lastname");
var lastname = lastnameInput.value;
9
Say Hi 1
// get the first name
var firstnameInput = document.getElementById("firstname");
var firstname = firstnameInput.value;
10
Say Hi 1
// construct the greeting message
var greetingMessage = "Hi " + firstname + " " + lastname + "!";
<span id="greeting"></span>
11
Say Hi 2
Adding a button “Clear”.
If the user clicks the “Clear” button then the texts in the input
fields and the greeting message are removed.
12
Say Hi 2
First name: <input type="text" id="firstname" /> <br /><br />
Last name: <input type="text" id="lastname" /> <br /><br />
<button onClick="sayHi()">Say Hi</button>
<button onClick="clearPage()">Clear</button> <br /><br />
<span id="greeting"></span>
13
Say Hi 2
function clearPage(){
// clear the firstname text field
14
Say Hi 2
// clear the firstname text field
var firstnameInput = document.getElementById("firstname");
firstnameInput.value = "";
<span id="greeting"></span> 15
Math Question
The user enters 2 numbers into the two text fields, then
selects the operation (+, - , x) from the drop-down list, then
clicks the “=” button, then answer will be generated.
16
Math Question
<input type="text" id="input1" />
<select id="operationSelect">
<option value="add">+</option>
<option value="subtract">-</option>
<option value="multiply">x</option>
</select>
<button onClick="answer()">
=
</button>
17
Math Question
function answer(){
// get the 1st number
// get the 2nd number
// get the operation
// calculate the result
// display the result
}
18
Math Question
// get the 1st number
var inputField1 = document.getElementById("input1");
var number1 = Number(inputField1.value);
19
Math Question
// calculate the result
var result;
if(operation == "add"){
result = number1 + number2;
}else if(operation == "subtract"){
result = number1 - number2;
}else if(operation == "multiply"){
result = number1 * number2;
}
20
Change style
<button onClick="changeHelloWorldStyle();">
Click me to change the style of the text
</button>
<span id="hello">Hello world</span>
<script>
function changeHelloWorldStyle(){
var helloSpan = document.getElementById("hello");
helloSpan.style.color = "orange";
helloSpan.style.fontSize = "30px";
helloSpan.style.fontStyle = "italic";
}
</script>
21
Passing parameters to function
Sometimes, it is useful to pass parameters to the function
22
New solution: using one function with parameter
Cat & Dog 1B
<button onClick="showMessage('Meao meao meao!')">Cat</button>
<button onClick="showMessage('Woof woof woof!')">Dog</button>
<br /> <br />
<span id="display"></span>
23
New solution: using one function with parameter
Cat & Dog 1B
function showMessage(message){
// get the span element
var displaySpan = document.getElementById("display");
i am for equality
whatever
24
Cat & Dog 2B
<button onClick="showMessage('Meao meao meao!')">Cat</button>
<button onClick="showMessage('Woof woof woof!')">Dog</button>
<br /> <br />
<input type="text" id="display" />
function showMessage(message){
// get the text field element
var displayField = document.getElementById("display");
25
Cat & Dog 3B
<button onClick="showImage('cat.png')">Cat</button>
<button onClick="showImage('dog.png')">Dog</button>
<br /> <br />
<img id="display" />
function showImage(imageFile){
// get the image element
var image = document.getElementById("display");
26
Random
To get a random (decimal) number from 0 (inclusive) to 1 (exclusive):
27
Random
Random decimal number from 0 1
Math.random()
28
Random
Random decimal number from 0 1
Math.random()
29
Dice 1
When the button is clicked, a random dice is displayed.
Math.floor(Math.random() * 6) + 1
30
Dice 1
<button onClick="rollDice()">
Roll the dice
</button>
<br />
31
Dice 1
function rollDice(){
// generate a random dice value from 1 to 6
var diceValue = Math.floor(Math.random() * 6) + 1;
dice5.png
32
Confirm box
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel".
33
Prompt box
When a prompt box pops up, the user will have to click either "OK" or "Cancel".
If the user clicks "OK" the box returns the input value.
prompt("sometext","defaultText");
34
Add subject 1
When the button is clicked, a prompt box appears asking the
user to enter a subject code. Then the subject is added to the
page.
35
Add subject 1
<button onClick="addSubject()">
Click here to add subject
</button>
<div id="subjectList">
</div>
36
Add subject 1
function addSubject(){
// ask user for a subject code
var subject = prompt("Enter subject code");
if(subject != null){
// create a new paragraph holding the subject code
var para = document.createElement("p");
var subjectText = document.createTextNode(subject);
para.appendChild(subjectText);
<div id="subjectList">
<p>MATH 111</p>
</div> 37
Add subject 2
When the button is clicked, a prompt box appears asking the
user to enter a subject code. Then the subject is added to the
page in an unordered list.
38
Add subject 2
<button onClick="addSubject()">
Click here to add subject
</button>
<ul id="subjectList">
</ul>
39
Add subject 2
function addSubject(){
// ask user for a subject code
var subject = prompt("Enter subject code");
if(subject != null){
// create a new list item holding the subject code
var li = document.createElement("li");
var subjectText = document.createTextNode(subject);
li.appendChild(subjectText);
40
Animation
Start an animation
specify 2 things:
clearInterval(animationSchedule);
41
Counter animation
When the “Start Counter” button is clicked, the counter
animation displays a number increasing every 1 second.
initially counter = 0
start animation
1000 milisec showCounter() counter = 1
1000 milisec showCounter() counter = 2
1000 milisec showCounter() counter = 3
1000 milisec showCounter() counter = 4
1000 milisec showCounter() counter = 5
……
stop animation 42
Counter animation
<button onClick="startCounterAnimation()">
Start counter
</button>
<button onClick="stopCounterAnimation()">
Stop counter
</button>
<font size="7">
<span id="counter"></span>
</font>
43
Counter animation
var counter = 0;
var counterSchedule;
function startCounterAnimation(){
Start an animation
44
what need to be done:
Counter animation write a function to do the task of the animation
function showCounter(){
45
Counter animation
function stopCounterAnimation(){
clearInterval(counterSchedule);
46
Dice 2 - animation
When the button is clicked, within 1 second, a flash of 10
random dice images are displayed, and then it stops.
<br />
48
Dice 2 - animation
var rollDiceSchedule;
var rollDiceCounter;
function rollDiceAnimation(){
// set the roll dice counter to 0
rollDiceCounter = 0;
Start an animation
49
what need to be done:
Dice 2 - animation write a function to do the task of the animation
function rollDice(){
// generate a random dice value from 1 to 6
var diceValue = Math.floor(Math.random() * 6) + 1;
● http://www.w3schools.com/js
● http://developer.mozilla.org/en-US/docs/Web/JavaScript
51
Introduction to Web Technology
1
XML and DTD
Objectives:
2
XML
● Using XML Document Type Definition (DTD), or XML Schema Definition (XSD),
different parties can agree on a standard XML format for interchanging data.
{
"firstName": "John",
"lastName": "Smith",
"email": "jsmith@gmail.com",
"mobile": "0211223344"
}
● In most web applications, XML and JSON are used to store or transport data,
while HTML and XSLT are used to transform and display the data. 4
XML:
The first example of XML:
5
XML: XML declaration
<?xml version="1.0" ?> XML declaration
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
</student>
● The XML declaration is optional and it must come first in the document.
● The XML declaration identifies the document as being XML. Even though it is
optional, all XML documents should begin with an XML declaration.
● The XML declaration must be situated at the first position of the first line in the
XML document.
○ Do not start an XML file with a blank line!!!
● Syntax for the XML declaration:
<?xml version="version_number"
encoding="encoding_declaration"
standalone="standalone_status" ?>
6
XML: root element
<?xml version="1.0" encoding="UTF-8" ?>
<student> root element
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
</student>
● An XML document must contain one root element that is the parent of all
other elements
<rootElement>
<child>
<subchild>.....</subchild>
</child>
</rootElement>
7
XML: root element
This is NOT a well-formed XML document because it has no root element
8
XML: root element
This is a well-formed XML document because it has a root element
9
XML: element
<tag attribute1="..." attribute2="...">
</tag>
<student_list>
...
</student_list>
or
<studentList>
...
</studentList>
11
XML: attribute
<tag attribute1="..." attribute2="...">
</tag>
<dailyTransaction date='24/02/2015'>
<person staffDbId="103" operation="update">
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
</person>
</dailyTransaction>
13
XML: relationship between elements
<parent>
<child>
<subchild>.....</subchild>
</child>
</parent>
● An XML tree starts at a root element and branches from the root to child
elements.
● The terms parent, child, and sibling are used to describe the relationships
between elements.
○ Parent have children. Children have parents.
○ Siblings are children on the same level
14
XML: attribute vs child element
Any attribute can be defined as a child element.
15
XML: attribute vs child element
Any attribute can be defined as a child element.
Metadata (data about data) should be stored as attributes, and the data itself
should be stored as elements.
<person gender="M">
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
</person>
<person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<gender>M</gender> this is better 17
</person>
XML: attribute vs child element
Any attribute can be defined as a child element, so when should we use attribute
and when should we use element?
Metadata (data about data) should be stored as attributes, and the data itself
should be stored as elements.
<person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
<staffDbId>103</staffDbId>
<operation>update</operation> this is better 18
</person>
XML: empty element and self-closing tag
In HTML, some elements might work well, even with a missing closing tag:
<br>
<hr>
<p>
<input ...>
19
XML: nested rule
In HTML, some elements might not be nested properly:
<b><i>This text is bold and italic</b></i>
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
</student>
20
XML: entity reference
If we place a character like < inside an XML element, it will generate an error.
In this case, we need to use the entity reference <
Entity references
21
XML: comments
Comments in XML:
22
DTD
● Using a DTD, different parties can agree on a standard XML format for
interchanging data.
23
DTD
The DTD can be declared inside the XML file, or it can be defined in a separate
file:
● Internal DTD
● External DTD
24
DTD: internal DTD
25
DTD: external DTD
27
DTD: external DTD
29
DTD: Element declaration
An element is everything from the element's start tag to the element's end tag:
<firstName>John</firstName>
<lastName>Smith</lastName>
30
DTD: Element declaration
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
</student>
31
DTD: Element declaration
<studentList>
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
33
DTD: Element declaration
Element content:
Example:
● elementName specifies the name of the element to which the attribute applies,
35
DTD: Attribute declaration
<!ATTLIST elementName attributeName attributeType attributeValue>
attributeValue
● is required
<!ATTLIST elementName attributeName attributeType #REQUIRED>
● is implied: if the attribute has no default value, has no fixed value, and is not
required, then it must be declared as implied
<!ATTLIST elementName attributeName attributeType #IMPLIED>
36
DTD: Attribute declaration
<?xml version="1.0" ?>
<dailyTransaction date="24/02/2015">
<person staffDbId="103" operation="update">
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
</person>
<person staffDbId="-1" operation="add">
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<mobile>0244556677</mobile>
</person>
</dailyTransaction>
● XML:
https://developer.mozilla.org/en-US/docs/Web/XML
● DTD:
https://msdn.microsoft.com/en-us/library
/ms256469(v=vs.110).aspx
38
Introduction to Web Technology
XSD
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
XSD
Objective:
2
XSD
● XML Schema Definition (XSD) is another way to define the legal building
blocks of an XML document. It defines the document structure with a list of
legal elements and attributes.
● Using a XSD, different parties can agree on a standard XML format for
interchanging data.
3
XSD: student example
XML file:
<?xml version="1.0" ?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" student.xsd">
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
</student>
<xsd:element name="student">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="mobile" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
4
</xsd:schema>
XSD: student example
XML file:
<?xml version="1.0" ?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="student.xsd">
<firstName>John</firstName>
<lastName>Smith</lastName> elements and data types used in the schema
<email>jsmith@gmail.com</email> come from the namespace
<mobile>0211223344</mobile> http://www.w3.org/2001/XMLSchema
</student>
<xsd:element name="student">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="mobile" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
5
</xsd:schema>
XSD: student example
XML file:
<?xml version="1.0" ?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="student.xsd">
<firstName>John</firstName>
<lastName>Smith</lastName> the elements and data types that come from
<email>jsmith@gmail.com</email> the namespace
<mobile>0211223344</mobile> http://www.w3.org/2001/XMLSchema
</student> should be prefixed with xsd
<xsd:element name="student">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstName" type=" xsd:string"/>
<xsd:element name="lastName" type=" xsd:string"/>
<xsd:element name="email" type=" xsd:string"/>
<xsd:element name="mobile" type=" xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
6
</xsd:schema>
XSD: student example
XML file:
<?xml version="1.0" ?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="student.xsd">
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
<mobile>0211223344</mobile>
</student>
<xsd:element name="student">
Complex type <xsd:complexType>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
Simple type <xsd:element name="email" type="xsd:string"/>
<xsd:element name="mobile" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
7
</xsd:schema>
XSD: element
8
XSD: complex type containing element
<result>
<mark>85</mark>
<grade>A</grade>
</result>
<xsd:element name="result">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="mark" type="xsd:integer"/>
<xsd:element name="grade" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
9
XSD: complex type containing element and attribute
<scan schedule="hourly">
<start>2018-06-20T13:00:00</start>
<finish>2018-06-20T13:01:47</finish>
<virusFound>true</virusFound>
</scan>
The attribute declarations
must always come last
<xsd:element name="scan">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="start" type="xsd:dateTime" />
<xsd:element name="finish" type="xsd:dateTime" />
<xsd:element name="virusFound" type="xsd:boolean" />
</xsd:sequence>
<xsd:attribute name="schedule" type="xsd:string" />
</xsd:complexType>
</xsd:element> 10
XSD: complex type containing attributes only
<price promotionCode="FAMILYDEAL">39.50</price>
<xsd:element name="price">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name="promotionCode" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
11
XSD: simple type containing no element, no attribute
<website>http://www.uow.edu.au/student</website>
<lastDayToEnrol>2000-03-24</lastDayToEnrol>
<favouriteColor>blue</favouriteColor>
12
XSD: simple type with restriction
<grade>B</grade>
Without restriction:
<xsd:element name="grade" type="xsd:string" />
With restriction:
<xsd:element name="grade">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
<xsd:enumeration value="D"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
13
XSD: simple type with restriction
<mark>84</mark>
Without restriction:
<xsd:element name="mark" type="xsd:integer" />
With restriction:
<xsd:element name="mark">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
14
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
<email>jsmith@gmail.com</email>
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
Let’s start with the root element studentList
<email>jsmith@gmail.com</email>
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
Let’s start with the root element studentList
<email>jsmith@gmail.com</email> ● it is a complex type
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
Let’s start with the root element studentList
<email>jsmith@gmail.com</email> ● it is a complex type
</student>
<student>
● which contains a sequence of student elements
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
Let’s start with the root element studentList
<email>jsmith@gmail.com</email> ● it is a complex type
</student>
<student>
● which contains a sequence of student elements
<firstName>Mary</firstName> ● studentList contains zero or unlimited
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
number of student elements
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
The element student is also a complex type
<email>jsmith@gmail.com</email>
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
The element student is also a complex type
<email>jsmith@gmail.com</email> ● which contains a sequence of elements
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
The element student is also a complex type
<email>jsmith@gmail.com</email> ● which contains a sequence of elements:
</student>
<student>
firstName, lastName, email
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
<?xml version="1.0" ?>
XSD: studentList example
<studentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentList.xsd">
<student>
<firstName>John</firstName>
<lastName>Smith</lastName>
firstName, lastName, email elements are all
<email>jsmith@gmail.com</email> simple type
</student>
<student>
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<email>mjane@gmail.com</email>
</student>
</studentList>
</xsd:schema>
XSD: dailyTransaction example
<?xml version="1.0" ?>
<dailyTransaction date="24/02/2015">
<person staffDbId="103" operation="update">
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
</person>
<person staffDbId="-1" operation="add">
<firstName>Mary</firstName>
<lastName>Jane</lastName>
<mobile>0244556677</mobile>
</person>
</dailyTransaction>
<xsd:element name="dailyTransaction">
<xsd:complexType>
<xsd:sequence>
...
</xsd:sequence>
<xsd:attribute name="date" type="xsd:string" />
</xsd:complexType>
</xsd:element>
26
XSD: dailyTransaction example
<dailyTransaction date="24/02/2015">
<person staffDbId="103" operation="update">
...
</person>
<person staffDbId="-1" operation="add">
...
</person>
</dailyTransaction>
<xsd:element name="dailyTransaction">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="person" minOccurs="0" maxOccurs="unbounded">
...
</xsd:element>
</xsd:sequence>
<xsd:attribute name="date" type="xsd:string" />
</xsd:complexType>
27
</xsd:element>
XSD: dailyTransaction example
<person staffDbId="103" operation="update">
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
</person>
28
XSD: dailyTransaction example
<person staffDbId="103" operation="update">
<firstName>John</firstName>
<lastName>Smith</lastName>
<mobile>0211223344</mobile>
</person>
● XSD: https://www.w3schools.com/xml/schema_intro.asp
● XSD: https://msdn.microsoft.com/en-us/library/ms256235(v=vs.110).aspx
30
Introduction to Web Technology
JSON
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
JavaScript: Array
var info = {
name: "John",
dob: new Date("1996-01-20"),
year: 2
};
{
"fullname": "John Smith",
"studentNumber": "U1234567",
"age": 20,
"csMajor": true
}
5
JSON
{
"fullname": "John Smith",
"studentNumber": "U1234567",
"age": 20,
"csMajor": true
}
6
JSON
[
{
"firstName":"John",
"lastName":"Smith"
},
{
"firstName":"Kate",
"lastName":"Williams"
}
]
7
JSON
● Curly braces hold objects
{
"firstName":"John",
"lastName":"Smith",
"subjectList":[
{
"code":"MATH101",
"title":"Algebra"
},
{
"code":"CSIT122",
"title":"C programming"
}
]
}
8
JSON
objJSON = JSON.stringify(obj);
obj = JSON.parse(objJSON);
9
JSON
OBJECT
{
fullname: "John Smith",
studentNumber: "U1234567",
age: 20,
csMajor: true
}
JSON.stringify
JSON.parse
JSON
{
"fullname": "John Smith",
"studentNumber": "U1234567",
"age": 20,
"csMajor": true 10
}
JSON.stringify
The JSON.stringify method converts a JavaScript value to a JSON string.
● space (Optional): use for indentation, specifying white spaces in the output
JSON string for readability purposes.
11
JSON.stringify function demo
12
JSON.stringify
var studentObj = {
fullname: "John Smith",
studentNumber: "U1234567",
age: 20,
csMajor: false
};
JSON.stringify(studentObj)
{"fullname":"John Smith","studentNumber":"U1234567","age":20,
"csMajor":false}
JSON.stringify(studentObj, null, 2)
{
"fullname": "John Smith",
"studentNumber": "U1234567",
"age": 20,
"csMajor": false
}
14
JSON.stringify
var studentObj = {
fullname: "John Smith",
studentNumber: "U1234567",
age: 20,
csMajor: false
};
{"studentNumber":"U1234567","csMajor":false}
15
JSON.stringify
var studentObj = {
fullname: "John Smith",
studentNumber: "U1234567",
age: 20,
csMajor: false
};
16
Example 1: JSON.stringify
function showObjectJSON(){
//create a student object
var studentObj = {};
studentObj.fullname = "John Smith";
studentObj.studentNumber = "U1234567";
studentObj.age = 20;
studentObj.csMajor = true;
<button onClick="showObjectJSON()">
Click here to see JSON string
</button>
17
Example 2: JSON.parse
function showObject(){
//JSON string
var studentJSON = '{"fullname":"John Smith","studentNumber":
"U1234567","age":20,"csMajor":true}';
<button onClick="showObject()">
Click here to see object from JSON
</button>
18
Example 3: JSON.stringify
function showArrayJSON(){
var user1 = {};
user1.firstName = "John";
user1.lastName = "Smith";
function showArray(){
//JSON string
var userListJSON = '[{"firstName":"John","lastName":"Smith"},
{"firstName":"Kate","lastName":"Williams"}]';
<button onClick="showArray()">
Click here to see array from JSON
</button>
20
Example 5: JSON.stringify
function showObjectJSON(){
var studentObj = {}; //create a student object
studentObj.firstName = "John";
studentObj.lastName = "Smith";
studentObj.subjectList = []; //empty array to hold subjects
{
"firstName":"John",
"lastName":"Smith",
"subjectList":[
{
"code":"MATH101",
"title":"Algebra"
},
{
"code":"CSIT122",
"title":"C programming"
}
]
}
22
References
● http://www.w3schools.com/json
● https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON
23
Introduction to Web Technology
HTML5:
Graphic Canvas,
Drag and Drop
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
HTML 5
Canvas
2
HTML 5
3
Canvas
4
Canvas
(0,0) x axis
There are other rendering contexts for canvas that are not
covered in this subject:
WebGLRenderingContext,
WebGL2RenderingContext
7
Hello World
8
Hello World
<button onClick="drawTextHello()">
Start
</button> 9
Hello World
function drawTextHello(){
// get the canvas's 2d context
// fillText
// strokeText
10
}
Hello World
<canvas id="canvas" width="1300" height="500"
style="border:1px solid black;">
Your browser does not support canvas.
</canvas>
// fillText
context.font = "italic small-caps bold 50px Arial";
context.fillText("Hello World", 200, 100);
// strokeText
context.font = "oblique 100px Courier New";
context.strokeText("Hello World", 250, 300);
12
Stroke Demo 1
13
Stroke Demo 1
<button onClick="strokeDemo()">
Start
</button>
14
Stroke Demo 1
function strokeDemo(){
// get the canvas's 2d context
15
Stroke Demo 1
16
Stroke Demo 1
(0,0)
X
// specify the path
context.beginPath();
context.moveTo(50, 10);
context.lineTo(50, 400);
context.lineTo(250, 400);
Y
17
Stroke Demo 1
18
Stroke Demo 2
19
Stroke Demo 2
context.beginPath();
context.moveTo(50, 10);
context.lineTo(50, 400);
context.lineTo(250, 400);
context.closePath();
20
Fill Demo 1
21
Fill Demo 1
function fillDemo(){
// get the canvas's 2d context
22
Fill Demo 1
23
Fill Demo 1
context.beginPath();
context.moveTo(50, 10);
context.lineTo(50, 400);
context.lineTo(250, 400);
context.closePath();
context.fillStyle="#F5FFFA";
context.fill();
24
Fill Demo 2
context.fillStyle="#F5FFFA";
context.fill(); 25
UOW
26
UOW
4. letter W
3. letter O (inner) filled with black
filled with white
1. letter U
filled with black 2. letter O (outer)
filled with black
27
UOW
<button onClick="drawUOW()">
Start 28
</button>
UOW
function drawUOW(){
// get the canvas's 2d context
// letter U
// letter O (outer)
// letter O (inner)
// letter W
}
29
// letter U
UOW
context.beginPath();
context.moveTo(0, 0);
context.lineTo(0, 350);
context.lineTo(50, 400);
context.lineTo(250, 400);
context.lineTo(300, 350);
context.lineTo(300, 0);
context.lineTo(200, 0);
context.lineTo(200, 280);
context.lineTo(180, 300);
context.lineTo(120, 300);
context.lineTo(100, 280);
context.lineTo(100, 0);
context.closePath();
30
// letter U
UOW
context.beginPath();
context.moveTo(0, 0);
...
context.lineTo(100, 0);
context.closePath();
context.fillStyle="black";
context.fill();
context.strokeStyle="blue";
context.lineWidth = "4";
context.stroke();
31
Drag and Drop
32
Drag and Drop
33
Drag and Drop
//dataTransfer object
event.dataTransfer.setData("dragId", dragId);
} 34
Drag and Drop
} 36
Drag and Drop
Calling the preventDefault() method during a dragOver event will indicate that a
drop is allowed at that location.
function dragOver(event){
event.preventDefault();
37
Drag and Drop: Hello World
38
Drag and Drop: Hello World
draggable elements:
elements that we can be
dragged
droppable elements:
elements that can be
dropped on
39
Drag and Drop: Hello World
draggable elements:
elements that we can drag
droppable elements:
elements that can be
dropped on
event.dataTransfer.setData("dragId", dragId);
42
}
Drag and Drop: Hello World
<span id="hello" draggable="true"
onDragStart="dragStart(event)" >hello</span>
event.dataTransfer.setData("dragId", dragId);
43
}
Drag and Drop: Hello World
Calling the preventDefault() method during a dragOver event will indicate that a
drop is allowed at that location.
function dragOver(event){
event.preventDefault();
45
References
● https://www.w3schools.com/html/html5_canvas.asp
● https://developer.mozilla.org/en-US/docs/Web/API/Canv
as_API/Tutorial
● https://www.w3schools.com/html/html5_draganddrop.asp
● https://developer.mozilla.org/en-US/docs/Web/API/HTML
_Drag_and_Drop_API
46
Introduction to Web Technology
Joseph Tonien
School of Computing and Information Technology
University of Wollongong
1
Client-Side Web Storage
● Store data on the client side, instead of the server
● Make the web application available offline
● The storage is per origin (protocol + domain + port)
● Simple storage: data is stored in name/value pair
2 types of storage:
● localStorage: a single persistent object which stores data with no
expiration date;
● sessionStorage: stores data for one session only, data is cleared when
the browser tab is closed.
2
Client-Side Web Storage
Checking if the browser supports web storage or not:
3
Client-Side Web Storage
Storing and retrieving data from Web Storage:
4
Example: To-Do-List (1)
We want to create a web application where the user can create a to-do-list and
save it to the local storage.
We will store the JSON of the task list into the local storage:
[
{
"task":"Grocery shopping",
"urgency":"Low"
},
Key Value {
"task":"Wash the dishes",
toDoListJSON [{"task":"Grocery "urgency":"Medium"
shopping","urgency": },
"Low"},...] {
"task":"Do web tech assignment 2",
"urgency":"High"
},
{
"task":"Do laundry",
"urgency":"Low"
} 5
]
Example: To-Do-List (1)
When the page load, we need to do the database initialization:
(i) get the to-do list JSON from the local storage,
(ii) parse the JSON.
<body onLoad="initApp();">
…
// initialize the application
function initApp(){
if (typeof(Storage) !== "undefined"){
} else{
console.log("Web Storage not supported");
}
}
6
Example: To-Do-List (1)
// to-do list which is saved to web storage
var toDoList = [];
function initApp(){
if (typeof(Storage) !== "undefined"){
} else{
console.log("Web Storage not supported");
}
}
7
Example: To-Do-List (1)
Adding a task to the to-do-list:
<body onLoad="initApp();">
Task:
<input id="task" type="text" />
Urgency:
<select id="urgency">
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low" selected="selected">Low</option>
</select>
<button onClick="addTask()">
Add
</button>
8
Example: To-Do-List (1)
Adding a task to the to-do-list:
// add a task
function addTask(){
// get task description from user input
var toDoObj = {};
toDoObj.task = document.getElementById("task").value;
toDoObj.urgency = document.getElementById("urgency").value;
9
Example: To-Do-List (1)
Showing all the tasks:
<button onClick="showTask()">
Show Task
</button>
<div id="taskDisplay">
</div>
10
Example: To-Do-List (1)
Showing all the tasks:
<div id="taskDisplay">
</div>
html += "Task: " + toDo.task + ", Urgency: " + toDo.urgency + "<br /><br />";
}
document.getElementById("taskDisplay").innerHTML = html;
} 11
Example: To-Do-List (2)
To-Do-List(2) example is the same as the previous To-Do-List(1) example, except
that each task is displayed with a color corresponding to its urgency level.
12
Example: To-Do-List (2)
document.getElementById("taskDisplay").innerHTML = html;
13
}
Example: To-Do-List (3)
To-Do-List(3) example is the same as the previous To-Do-List(2) example, except
that each task is displayed with a delete symbol, and when the user clicks on the
delete symbol the task will be deleted.
14
Example: To-Do-List (3)
We will use an image delete.png for the delete symbol.
15
Example: To-Do-List (3)
// show all the tasks
function showTask(){
var html = "";
if(toDo.urgency == "Low"){
html += "<span style='color:green'>" + toDo.task + "</span>";
}else if(toDo.urgency == "Medium"){
html += "<span style='color:orange'>" + toDo.task + "</span>";
}else if(toDo.urgency == "High"){
html += "<span style='color:red'>" + toDo.task + "</span>";
}
document.getElementById("taskDisplay").innerHTML = html;
16
}
Example: To-Do-List (3)
// delete a task
function deleteTask(task){
if(toDo.task == task){
toDoList.splice(i, 1);
break;
}
}
18
Example: To-Do-List (4)
<body onLoad="initApp();">
…
// initialize the application
function initApp(){
if (typeof(Storage) !== "undefined"){
} else{
console.log("Web Storage not supported");
} 19
}
Example: To-Do-List (4)
// to-do list which is saved to web storage
var toDoList = [];
function initApp(){
if (typeof(Storage) !== "undefined"){
} else{
console.log("Web Storage not supported");
}
20
}
Example: To-Do-List (4)
Adding a task to the to-do-list:
// add a task
function addTask(){
// get task description from user input
var toDoObj = {};
toDoObj.task = document.getElementById("task").value;
toDoObj.urgency = document.getElementById("urgency").value;
if(toDo.task == task){
toDoList.splice(i, 1);
break;
}
}
23
Example: Math Practice
This is how the application should work.
When the user clicks on the button “Start Math Practice”, the user will be asked
to enter his/her name.
24
Example: Math Practice
Then the application prints a greetings and generate a math question.
25
Example: Math Practice
User can enter an answer to the math problem and can check if it is correct.
26
Example: Math Practice
Parents can click on the button “View Math Practice History” to see the result of
their kids practice.
27
Example: Math Practice
Parents can enter a name to search
28
References
● https://www.w3.org/TR/webstorage/
● https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
29