Syllabus Content:: Sec 1.2.3 Client - and Server-Side Scripting
Syllabus Content:: Sec 1.2.3 Client - and Server-Side Scripting
Syllabus Content:: Sec 1.2.3 Client - and Server-Side Scripting
Syllabus Content:
1.2.3 Client- and server-side scripting
describe the sequence of events executed by the client computer and web server when
a web page consisting only of HTML tags is requested and displayed by a browser
Client-side
o recognise and identify the purpose of some simple JavaScript code
o describe the sequence of events executed by the client computer and web server
when a web page with embedded client-side code is requested and displayed by
a browser
o show understanding of the typical use of client-side code in the design of an
application
Server-side
o recognise and identify the purpose of some simple PHP code
o describe the sequence of events executed by the client computer and web server
when a web page with embedded server-side code is requested and displayed
by a browser
o show understanding that an appropriately designed web application for
accessing database data makes use of server-side scripting
1
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
Once the page is displayed the user can activate the application by clicking on a
suitable feature or by entering data as appropriate.
HTML We now need to consider the framework for creating a file using HTML. This is a
text file constructed using pairs of what are referred to as 'tags'. The basic overall
structure can be represented as:
<html>
<head>
</head>
<body>
…
…
…
</body>
</html>
In between each pair of opening and closing tags there can be any number of lines of
text. These can be used to display on the browser screen any or all of the following:
text, images, videos, forms, hyperlinks, icons and so on.
The facilities offered by HTML can be supplemented by the inclusion of scripted code,
written in JavaScript or PHP.
JavaScript
JavaScript is written by the application developer into the HTML text but its effect
is to allow the user at the client end to interact with the application and to cause
processing to take place on the client computer.
The browser must have JavaScript enabled.
In the early days of the use of JavaScript it was necessary to ensure this and to
include explicit reference to the use of JavaScript in the HTML file.
JavaScript is now the default scripting language so a script runs automatically.
The important point is that this has nothing to do with what is installed on the
server.
JavaScript file is saved with .html extension
One way to incorporate JavaScript is to write the code in a separate file which is then
called from within the HTML. Here we only consider the case when JavaScript code is
contained within the HTML itself. This is easily done (and1 easily recognised in an
example HTML file) by containing the script in script tags:
2
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
JavaScript Code
<html>
<head>
<title> JAVASCRIPT Lesson </title>
</head>
<body>
<h1>
You've Just executed a Javascript code.
</h1>
<script>
var fname = window.prompt("Please Enter your First Name", " ");
var lname = prompt("Please Enter your last name", " ");
var answer = (fname + lname);
window.alert ("The answer is "+ answer);
</script>
</body>
</html>
When executing JavaScript code, it will generate prompts and get user input
Calculate answer at client computer
Display answer on screen.
3
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
PHP
PHP is also a full-blown computer programming language.
The difference is that any PHP script is processed on the server. As for
JavaScript, the PHP can be contained in a separate file accessed by the HTM L.
The example considered here will have the script written inside the file containing
the HTML. In this case the HTML file must be named with a .php extension
rather than the usual .html extension.
The PHP code is included within special tags:
The JavaScript program shown in the previous section could be converted to PHP to
run on the server in the following way:
4
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
As before this simple example shows how to identify some PHP code within
HTML and see what it is doing.
It is worth noting that variables start with $and they are case sensitive.
The first character has to be in lower case so $ _ GET, which is the method for
getting the parameter value, can be recognised as not being a variable.
EXAM QUESTIONS
9608/12/M/J/17
Q6
(c) The following web page used for data capture consists of:
5
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
(i) The developer has used three variables in the JavaScript code. State the identifiers used.
1. ....................................
2. ....................................
3. .................................... [2]
(ii) The button has an event whose identifier is onMouseDown. When the mouse button is
clicked, some code is run. State the line numbers which contain this code.
6
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
(iv) Describe the purpose of the validation check that the code performs.
...........................................................................................................................................
.......................................................................................................................................[1]
(v) Name and describe two other types of validation check which could be appropriate for
this data capture form.
Description ........................................................................................................................
...........................................................................................................................................
Description ........................................................................................................................
........................................................................................................................................... [4]
7
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir
9608/12/M/J/17
Answer