Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Syllabus Content:: Sec 1.2.3 Client - and Server-Side Scripting

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Computer Science 9608

Sec 1.2.3 Client – and Server–side scripting


with Majid Tahir

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

Scripting and HTML in a client-server application


It is possible for an individual to create a client- server-based web application for
personal use on an individual computer.
This would require downloading appropriate server software, installing the application
and using the computer's browser to access the application. However, a better
understanding is gained by considering a scenario where a developer has created a
web application and made it available for use by remote users.
The application developer has to create the application as one or more web pages.
This is a three-stage process.
Firstly, for each web page a file has to be created which is written in HTML
(HyperText Markup Language).
Secondly, a domain name has to be obtained from a web-hosting organisation.
Finally, the HTML files have to be uploaded to the server provided by the web-
hosting organisation.
The following is the simplest sequence of events associated with a user accessing the
application:
1. The user opens up a browser on the client computer.
2. The user types in the URL of the web application or selects it from the bookmark
list.
3. The browser asks the DNS system for the IP address.
4. The browser connects to the IP address and sends a request for the web page.
5. The page is sent by the server to the browser.
6. The browser displays the page.

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

When would a developer want to use JavaScript?


Whenever the developer wants the user to have processing carried out on the
client computer
Any process which does not involve the software running on the server.
This might involve running a program as illustrated by the above simple example.
More often the JavaScript is used for collecting data which is to be used by a
program running on the server.
In particular, data validation and verification can be handled using JavaScript

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.

When would a developer want to use PHP?


The main question is, again, why would a developer choose to include PHP script in
some HTML?
The answer is that an application will not run quickly if it is constantly transmitting
data back and forward between the client computer and the server.
For the particular case of a database application it is imperative that the
database remains on the server (or within the system of which the server is part)
and that only the results of queries are displayed on a browser screen.
Also any SQL associated with the use of the database needs to be running on
the server not on the client.
An example of this will be considered as data extracted from Database in SQL
via Query and only result displayed to the user.

EXAM QUESTIONS
9608/12/M/J/17
Q6
(c) The following web page used for data capture consists of:

two text boxes for the entry of:


o A race runner’s ID code
o Their finishing position in a race.
A button that the user clicks to submit this runner’s result

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.

From line .................................... to line .................................... [1]

6
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir

(iii) The JavaScript code uses a selection statement.

State the line number which contains its condition.

Line number: .................................... [1]

(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.

Validation check: ...............................................................................................................

Description ........................................................................................................................

...........................................................................................................................................

Validation check: ...............................................................................................................

Description ........................................................................................................................

........................................................................................................................................... [4]

7
Computer Science 9608
Sec 1.2.3 Client – and Server–side scripting
with Majid Tahir

9608/12/M/J/17
Answer

You might also like