UNIVERSITY OF COLOMBO, SRI LANKA
UNIVERSITY OF COLOMBO SCHOOL OF COMPUTING
DEGREE OF BACHELOR OF INFORMATION TECHNOLOGY (EXTERNAL)
Academic Year 2018 – 2nd Year Examination – Semester 3
IT3505 – Web Application Development II
PART 2 – Structured Question Paper
13th May, 2018
(ONE HOUR)
To be completed by the candidate
BIT Examination Index No:
Important Instructions:
The duration of the paper is 1 (one) hour.
The medium of instruction and questions is English.
This paper has 2 questions and 9 pages.
Answer all questions. Questions do not carry equal marks.
Write your answers in English using the space provided in this question paper.
Do not tear off any part of this answer book.
Under no circumstances may this book, used or unused, be removed from the
Examination Hall by a candidate.
Note that questions appear on both sides of the paper.
If a page is not printed, please inform the supervisor immediately.
Calculators are not allowed.
Questions Answered
Indicate by a cross (), (e.g.
1 ) the numbers of the questions answered.
Question numbers
To be completed by the candidate by
1 2
marking a cross ().
To be completed by the examiners:
All Rights Reserved
1
Index No ………………………….
(1) a) Explain the functionality of the following JavaScript code.
$(document).ready(function(){
$("p").click(function(){
$(this).css("color", "red");
});
});
(10 Marks)
ANSWER IN THIS BOX
Add a function to all paragraphs after the document is loaded,
to change the colour of the paragraph to red when the mouse is clicked over the paragraph
2
Index No ………………………….
Parts (b) and (c) of this question are based on the following HTML script. Assume that the
script is saved with the name “index.php” in the “DOCUMENT ROOT” folder of your
computer where the Apache webserver runs.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Record Data </title>
<script src="jquery.js"></script>
</head>
<body>
<h2> Registration Form </h2>
<form id='myForm' action="index.php" method="POST">
<table border=”1”>
<tr>
<td>Registration number</td>
<td><input id='regno' type="text" name="rno"></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name=”submit” value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
3
Index No ………………………….
b) Draw the layout of the page displayed when the HTML script is rendered.
(20 Marks)
ANSWER IN THIS BOX
4
Index No ………………………….
c) Assume that the following code segment is embedded in the header section of the above
HTML script.
<script>
$(document).ready(function(){
$('#myForm').submit(function(e){
e.preventDefault();
if ($('#regno').val()=='') {
alert("Invalid form data");
} else {
alert("Form submitted");
this.submit();
}
});
})
</script>
Explain the key parts and the functionality of the above code.
(20 Marks)
ANSWER IN THIS BOX
When the user clicked the submit button, the code will check whether the regno
filed is blanked or not.
If the regno field is blank
it issues the message “Invalid form data”
Blocked the submission
If the regno field is not blank
The page is submitted
5
Index No ………………………….
(2) All parts of this question are based on the following MySQL database table “student” in a
database named ‘school’. The id column is the primary key of the table.
student table
id name gender class
95001 Saman m 2A
95002 Kumar m 2A
95003 Kamala f 2D
Consider the following incomplete PHP script coded to retrieve data from the table student
in the database school.
<?php
class School{
private $link;
function __construct(){
$this->link =
new mysqli('localhost','root','root123','school');
}
/* return the name of the student given his/her id
If the id is not in the table the message ‘Student not found’
Should be returned
*/
public function getStudent($id){
/* return the names of all students as an un-orderd HTML list,
give the class and gender.
*/
public function getStudentinClass($class,$gender){
$student = new School();
?>
6
Index No ………………………….
a) (i) What is the name of the constructor of the PHP class School?
(4 Marks)
ANSWER IN THIS BOX
Name of the constructor - __construct()
(ii) Clearly explain the functionality of the constructor.
(6 Marks)
ANSWER IN THIS BOX
Main functionality:
Open a connection to the database school.
Assign the connection to a private variable $link
7
Index No ………………………….
b) Write php code to fill the body of the function getStudent($id).
(15 Marks)
ANSWER IN THIS BOX
public function getStudent($id){
$sql = "select name from student where id = '$id'";
$result = $this->link->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
return $row["name"];
}else {
return 'Student not found';
8
Index No ………………………….
c) Write php code to fill the body of the function getStudentinClass($class,$gender)
.
(25 Marks)
ANSWER IN THIS BOX
public function getStudentinClass($class,$gender){
$sql = "select name from student where class = '$class' and
gender='$gender'";
$list ='<ul>';
$result = $this->link->query($sql);
while($row = $result->fetch_assoc()){
$list = $list . "<li>". $row["name"]. "</li>";
}
$list = $list . "</ul>";
return $list;
*******************