Web Programming Exit Exam
Web Programming Exit Exam
TUTORIAL
WEB PROGRAMMING
Web Design and Development I and II
1
Review concepts
Content Categorization
Selecting focus area
Tip and tricks
Doing sample questions
Web Design:
Refers to both the visual portion of the website and it’s usability.
Use various design programs such as Adobe Photoshop to create the
layout and other visual elements of the website
Web Developers
Take a website design and actually make a functioning website
from it.
Web developers use HTML, CSS, JavaScript, PHP and other
programming languages to bring to life the design files.
Key Points
When client sends request for a web page, the web server search
for the requested page . . .
If requested page is found then it will send it to client with an HTTP
response.
If the requested web page is not found, web server will the send
an HTTP response:Error 404 Not found.
If client has requested for some other resources then the web server
will contact to the application server and data store to construct the
HTTP response.
Features of HTML
It is easy to learn and easy to use.
It is platform independent.
Images, video and audio can be added to a web page.
Hypertext can be added to text.
It is a markup language.
An HTML document can be created using any text editor . Save the text
file using .html or .htm
<!DOCTYPE!>
This is the document type declaration (not technically a tag). It declares a
document as being an HTML document. The doctype declaration is not case-
sensitive.
<html>
This is called the HTML root element. All other elements are contained within it.
<head>
The head tag contains the “behind the scenes” elements for a webpage.
<body>
The body tag is used to enclose all of the visible content of a webpage. In other
words, the body content is what the browser will show on the front-end.
Image: <IMG>
Attributes:
SRC, ALT ,ALIGN
Adding text
Text input: <INPUT type=‘text’>
Password input: <INPUT type=‘password’>
Text area: <TEXTAREA>…</TEXTAREA>
Making Choices
Radio buttons: <INPUT type=‘radio’>
Checkboxes: <INPUT type=‘checkbox’>
Dropdown boxes: <SELECT> . . . </SELECT>
Options: <OPTION>..</OPTION>
Submitting forms
Submit buttons: <INPUT type=‘SUBMIT’>
Images buttons: <INPUT type=‘IMAGE’>
Uploading files
File upload: <INPUT type=‘FILE’>
Buttons & Hidden Controls
Button: <BUTTON>
Hidden control: <INPUT type=‘HIDDEN’>
Grouping form elements
<FIELDSET> … </FIELDSET>
<LEGEND> … </LEGEND>
HTML Validations
Date: <INPUT type=‘DATE’>
Email: <INPUT type=‘EMAIL’>
URL: <INPUT type=‘URL’>
Search: <INPUT type=‘SEARCH’>
Extra Markup
Comment: <!-- -->
Attributes
ID
NAME
CLASS
Block Elements
<DIV>
Inline Elements
<SPAN>
Iframes
<IFRAME>
CSS allows you to create rules that specify how the content of
an element should appear.
The key to understanding how CSS works is to imagine that there is
an invisible box around every HTML element
CSS allows you to create rules that control the way that each
individual box (and the contents of that box) is presented.
BLOCK & INLINE ELEMENTS
Block level elements look like they start on a new line.
Inline elements follow within the text and don’t start on a new line.
hex codes These are six-digit codes that represent the amount of red,
green and blue in a color, preceded by a pound or hash # sign.
For example: #ee3e80
color names There are 147 predefined color names that are
recognized by browsers.
For example: DarkCyan
Foreground Color
The color property allows you to specify the color of text inside an
element.
Background Color
CSS treats each HTML element as if it appears in a box, and the
background-color property sets the color of the background for that
box.
CSS3 Opacity: opacity, rgba
CSS3 introduces the opacity property which allows you to specify
the opacity of an element and any of its child elements.
The value is a number between 0.0 and 1.0 (so a value of 0.5 is 50%
opacity and 0.15 is 15% opacity).
The properties that allow you to control the appearance of text can
be split into two groups:
Those that directly affect the font and its appearance
Those that would have the same effect on text no matter what font you
were using
Specifying Typefaces
The font-family property allows you to specify the typeface that should
be used for any text inside the element(s) to which a CSS rule applies.
font-size
The font-size property enables you to specify a size for the font. There
are several ways to specify the size of a font. The most common are:
Bold font-weight
The font-weight property allows you to create bold text. There are
two values that this property commonly takes:
normal This causes text to appear at a normal weight.
bold This causes text to appear bold.
Italic font-style
If you want to create italic text, you can use the font-style property.
There are three values this property can take:
normal This causes text to appear in a normal style (as opposed to italic
or oblique).
italic This causes text to appear italic.
oblique This causes text to appear oblique
Leading line-height
Leading (pronounced ledding) is a term typographers use for the
vertical space between lines of text.
Letter & Word Spacing
You can control the space between each letter with the letter-spacing
property.
You can also control the gap between words using the word-spacing
property.
Alignment text-align
The text-align property allows you to control the alignment of text.
Vertical Alignment
It is more commonly used with inline elements such as <img>,
<em>, or <strong> elements.
The values it can take are: baseline, sub, super, top, text-top,
middle, bottom, text-bottom
Indenting Text text-indent
The text-indent property allows you to indent the first line of text
within an element.
CSS3: Drop Shadow
The text-shadow property has become commonly used despite
lacking support in all browsers.
You can set several properties that affect the appearance of these
boxes.
Control the dimensions of your boxes
Create borders around boxes
Set margins and padding for boxes
Show and hide boxes
Box dimensions
By default a box is sized just big enough to hold its contents.
To set your own dimensions for a box you can use the height and
width properties.
The padding property allows you to specify how much space should
appear between the content of an element and its border.
The margin property controls the gap between boxes. Its value is
commonly given in pixels, although you may also use percentages or
ems.
Centering Content
If you want to center a box on the page (or center it inside the
element that it sits in), you can set the left-margin and right-margin
to auto.
Change inline/block
The display property allows you to turn an inline element into a
block-level element or vice versa, and can also be used to hide an
element from the page.
Hiding Boxes
The visibility property allows you to hide boxes from users but It
leaves a space where the element would have been.
This property can take two values:
hidden This hides the element.
visible This shows the element.
CSS3-Border Images
The border-image property applies an image to the border of any
box. It takes a background image and slices it into nine pieces.
CSS3: Rounded Corners
CSS3 introduces the ability to create rounded corners on any box,
using a property called border-radius. The value indicates the size
of the radius in pixels.
Lists
Bullet point styles
The list-style-type property allows you to control the shape or style of a
bullet point (also known as a marker).
Unordered Lists
none, disc circle, square
Ordered Lists
decimal, decimal-leading-zero, lower-alpha, upper-alpha, lower-roman, upper-
roman
Tables
Here are some tips for styling tables to ensure they are clean and easy
to follow:
Give cells padding: adding padding helps to improve readability.
Distinguish headings: Putting all table headings in bold makes them
easier to read.
Shade alternate rows: shading every other row can help users follow
along the lines.
Align numerals: you can use the text-align property to align the content
of any column that contains numbers to the right
Styling Form
It is most common to style:
Text inputs and text areas
Submit buttons
Labels on forms, to get the form controls to align nicely
Styling Text Inputs
font-size: sets the size of the text entered by the user. color: sets the text color,
and background-color sets the background color of the input.
border: adds a border around the edge of the input box, and border-radius can
be used to create rounded corners.
The :focus is used to change the background color of the text input when it is
being used, and the :hover applies the same styles when the user hovers over
them
background-image: adds a background image to the box.
Images
You can control the size of an image using the width and height
properties in CSS, just like you can for any other box
Aligning images
Use the float property to align images
float: right/left
Background images
The background property acts like a shorthand for all of the other
background properties you have just seen, and also the background-color
property.
Overlapping Elements
If you want to control which element sits on top, you can use the z-
index property.
Its value is a number, and the higher the number the closer that element
is to the front.
Getting Input
prompt() is a method of the window object.
When JavaScript sees this prompt("...") it will open a dialog box.
Displaying Output
Using document.write().
The word document refers to the HTML page that contains this
JavaScript program.
It is an object, one of the most famous objects in the JavaScript
language.
Using console.log().
Using alert().
Normally, statements in a program execute one after the other in the order
in which they are written.
This process is called sequential execution.
Various JavaScript statements enable the programmer to specify that the
next statement to execute may not be the next one in sequence.
This is known as transfer of control.
Here are the control structures
if . . . else if … else selection statement
switch multiple-selection statement
while repetition statement
for repetition statement
do…while Repetition Statement
break and continue Statements
Andargachew A. [HiLCoE] 11/24/2023
65 Client Side Scripting (JS)
5. Array in JavaScript
Function Expression
JavaScript allows us to assign a function to a variable and then use that
variable as a function. It is called function expression.
Anonymous Function
JavaScript allows us to define a function without any name.
This unnamed function is called anonymous function. Anonymous function
must be assigned to a variable.
With the HTML DOM, JavaScript can access and change all the
elements of an HTML document.
When a web page is loaded, the browser creates
a Document Object Model of the page.
With the object model, JavaScript gets all the power it needs to create
dynamic HTML:
JavaScript can change all the HTML elements in the page
JavaScript can change all the HTML attributes in the page
JavaScript can change all the CSS styles in the page
JavaScript can remove existing HTML elements and attributes
JavaScript can add new HTML elements and attributes
JavaScript can react to all existing HTML events in the page
JavaScript can create new HTML events in the page
Andargachew A. [HiLCoE] 11/24/2023
70
Changing CSS
The HTML DOM allows JavaScript to change the style of HTML
elements.
Changing HTML Style
To change the style of an HTML element, use this syntax:
document.getElementById(id).style.property = new style
JavaScript Events
An HTML event can be something the browser does, or something a
user does. Here are some examples of HTML events:
An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked
PHP COOKIE
A cookie is a small file with the maximum size of 4KB that the web
server stores on the client computer.
Once a cookie has been set, all page requests that follow return the
cookie name and value.
A cookie can only be read from the domain that it has been issued
from.
For example, a cookie set using the domain www.hilcoe.net can not be
read from the domain www.aau.edu.et
A cookie created by a user can only be visible to them. Other users
cannot see its value.
Creating Cookie
A cookie is created with the setcookie() function.
PHP SESSION
A session is a global variable stored on the server.
Each session is assigned a unique id which is used to retrieve stored
values.
Whenever a session is created, a cookie containing the unique
session id is stored on the user’s computer and returned with
every request to the server.
If the client browser does not support cookies, the unique php session id
is displayed in the URL.
Sessions have the capacity to store relatively large data compared
to cookies.
Creating a Session
In order to create a session, you must first call the PHP session_start
function and then store your values in the $_SESSION array
variable.
Destroying session Variables
The session_destroy() function is used to destroy the whole PHP
session variables.
If you want to destroy only a session single item, you use the unset()
function.
session_destroy(); //destroy entire session
PHP PDO
The PHP Data Objects (PDO) defines a lightweight interface for
accessing databases in PHP.
It provides a data-access abstraction layer for working with databases
in PHP.
It defines consistent API for working with various database systems.
Mode Purpose
r Opens the file for reading only. Places the file pointer at the beginning of the file.
r+ Opens the file for reading and writing. Places the file pointer at the beginning of the file.
w Opens the file for writing only. Places the file pointer at the beginning of the file. and
truncates the file to zero length. If files does not exist then it attempts to create a file.
w+ Opens the file for reading and writing only. Places the file pointer at the beginning of the
file. and truncates the file to zero length. If files does not
exist then it attempts to create a file.
a Opens the file for writing only. Places the file pointer at the end of the file. If files does not
exist then it attempts to create a file.
a+ Opens the file for reading and writing only. Places the file pointer at the end of the file. If
files does not exist then it attempts to create a file.
Andargachew A. [HiLCoE] 11/24/2023
110
Reading a file
Once a file is opened using fopen() function it can be read with a function
called fread().
This function requires two arguments.
These must be the file pointer and the length of the file expressed in bytes.
The files length can be found using the filesize() function which takes the
file name as its argument and returns the size of the file expressed in bytes.
So here are the steps required to read a file with PHP.
Open a file using fopen() function.
Get the file's length using filesize() function.
Read the file's content using fread() function.
Close the file with fclose() function.
Writing a file
A new file can be written or text can be appended to an existing file
using the PHP fwrite() function.
This function requires two arguments specifying a file pointer and
the string of data that is to be written.
Optionally a third integer argument can be included to specify the
length of the data to write.
If the third argument is included, writing would will stop after the
specified length has been reached.
You can include the content of a PHP file into another PHP file
before the server executes it.
There are two PHP functions which can be used to included one
PHP file into another PHP file.
The include() Function
The require() Function
This helps in creating functions, headers, footers, or elements that
can be reused on multiple pages.
Easy to change the layout of complete website with minimal effort.
Get a Date
The format parameter of the date() function specifies hrequiredow to format
the date (or time).
Here are some characters that are commonly used for dates:
d - Represents the day of the month (01 to 31)
D – Represents day of the week (Mon to Sun).
m - Represents a month (01 to 12)
M – Represents month in text,(Jan to Dec).
Y - Represents a year (in four digits)
y – Represents year in two digits (08 or 14).
l (lowercase 'L') - Represents the day of the week
Other characters, like"/", ".", or "-" can also be inserted between the
characters to add additional formatting.
Get a Time
Here are some characters that are commonly used for times:
H - 24-hour format of an hour (00 to 23)
h - 12-hour format of an hour with leading zeros (01 to 12)
i - Minutes with leading zeros (00 to 59)
s - Seconds with leading zeros (00 to 59)
a - Lowercase Ante meridiem and Post meridiem (am or pm)
A - Uppercase Ante meridiem and Post meridiem (AM or PM)
Define a Class
A class is defined by using the class keyword, followed by the name
of the class and a pair of curly braces ({}).
Note: In a class, variables are called properties and functions are
called methods!
All its properties and methods go inside the braces:
Define Objects
Each object has all the properties and methods defined in the class,
but they will have different property values.
Objects of a class is created using the new keyword.
1. Inside the class (by adding a 2. Outside the class (by directly
set_name() method and use changing the property value):
$this):
Access Modifiers
Properties and methods can have access modifiers which control
where they can be accessed.
There are three access modifiers:
public - the property or method can be accessed from everywhere.
(This is default)
protected - the property or method can be accessed within the class and
by classes derived from that class
private - the property or method can ONLY be accessed within the
class
Data can be retrieved from the server and only a certain part of
a page updated without loading the whole page.
This is very useful for web page parts that load things like
Tweets
Comments
Users visiting the site etc
Method Description
new XMLHttpRequest() Creates a new XMLHttpRequest object
abort() Cancels the current request
getAllResponseHeaders() Returns header information
getResponseHeader() Returns specific header information
open(method, url, async, Specifies the request
user, psw) method: the request type GET or POST
url: the file location
async: true (asynchronous) or false (synchronous)
user: optional user name
psw: optional password
Get Requests
Example
xhttp.open("GET", "demo.php", true);
xhttp.send();
If you want to send information with the GET method, add the
information to the URL:
Post Requests
Example
xhttp.open("POST", “test.php", true);
xhttp.send();
To POST data like an HTML form, add an HTTP header
with setRequestHeader(). Specify the data you want to send in
the send() method:
Seen from a Document Type Definition (DTD) point of view, all XML
documents are made up by the following building blocks:
Elements
It is the main building blocks of both XML and HTML documents.
Attributes
It provides extra information about elements.
Entities
Some characters have a special meaning in XML, like the less than sign (<)
that defines the start of an XML tag
PCDATA (Parsed Character Data)
The text will be examined by the parser for entities and markup.
CDATA (Character Data)
Text that will NOT be parsed by a parser
Andargachew A. [HiLCoE] 11/24/2023
150 Introduction to XML
3. XML Schema
RDF
RDF stands for Resource Description Framework
RDF is a framework for describing resources on the web
RDF is written in XML
RDF is a W3C Recommendation
RSS
RSS stands for Really Simple Syndication
RSS allows you to syndicate your site content
RSS defines an easy way to share and view headlines and content
RSS files can be automatically updated
RSS allows personalized views for different sites
Andargachew A. [HiLCoE] 11/24/2023
RSS is written in XML
153
Questions?
Thank You