Blog
Web Technologies Past Paper 2026 – BS IT 4th Semester UOS (ITDC-5201)
University of Sargodha AD/BS IT 4th semester Web Technologies (ITDC-5201) paper, 2026 exam (60 marks, 2:30 hours). Solved answers are given below for all 12 short questions and all five long questions, including a tested JavaScript dropdown search program, GET vs POST, OOP in JavaScript, XML vs JSON and AJAX with a fetch example.
Solved answers
Q1 – Short answers (12 × 2)
i. Text box vs text area: A text box (<input type=”text”>) accepts a single line of text such as a name; a text area (<textarea rows cols></textarea>) accepts multiple lines, such as comments or an address.
ii. How JavaScript adds interactivity: It runs in the browser and reacts to user events (click, input, submit), changes the page through the DOM without reloading, validates forms, shows/hides content, creates animations and fetches data from the server (AJAX).
iii. Starting a session in PHP: Call session_start(); at the top of the page before any output, then store values: $_SESSION["user"] = "Ali";.
iv. Key functionalities of a web browser: Sending HTTP/HTTPS requests to web servers, rendering HTML/CSS and running JavaScript, navigation (back, forward, bookmarks, history), managing tabs, cookies and cache, downloads, security (certificates, blocking unsafe sites) and extensions.
v. DHTML vs AJAX: DHTML (Dynamic HTML) combines HTML, CSS, JavaScript and the DOM to change the page on the client side without contacting the server. AJAX (Asynchronous JavaScript and XML) uses XMLHttpRequest/fetch to exchange data with the server in the background and update part of the page without a full reload.
vi. Role of phpMyAdmin: A free web-based tool, written in PHP, to manage MySQL/MariaDB databases through a browser – create databases and tables, run SQL queries, insert/edit data, manage users and privileges, and import/export (backup) data.
vii. Cookie in PHP: A small piece of data stored by the server in the user’s browser and sent back with each request, used to remember users and preferences. Example: setcookie("user", "Ali", time() + 86400); (expires in one day).
viii. Inline vs block elements: Block elements start on a new line and take the full available width (<div>, <p>, <h1>, <ul>); inline elements stay in the same line and take only the width of their content (<span>, <a>, <b>, <img>).
ix. Static vs dynamic web pages: A static page shows the same fixed HTML content to every user until the developer changes the file. A dynamic page is generated at request time (by PHP, ASP.NET, Node.js with a database) or changed by JavaScript, so content can differ by user, time or input – e.g. a results portal.
x. Display current date in a paragraph: <p id="d"></p> <script> document.getElementById("d").innerHTML = new Date().toDateString(); </script>
xi. HTML vs XHTML: XHTML is HTML written with XML rules: tags and attributes must be lowercase, every element must be closed (<br />), elements properly nested, attribute values quoted, and a single root element; HTML is more lenient and browsers tolerate errors.
xii. Importance of CSS: CSS separates presentation from content, so one style sheet controls the layout, colours and fonts of a whole site; it reduces code repetition, makes maintenance easier, gives consistent design, enables responsive layouts (media queries) for mobiles and speeds up loading through caching.
Q2 – JavaScript: search a city in a dropdown and replace it with “CS&IT”
<!DOCTYPE html>
<html>
<head><title>City Search</title></head>
<body>
<select id="cities">
<option>Lahore</option>
<option>Karachi</option>
<option>Sargodha</option>
<option>Islamabad</option>
<option>Multan</option>
</select>
<input type="text" id="cityName" placeholder="Enter city name">
<button onclick="searchCity()">Search & Replace</button>
<p id="result"></p>
<script>
function searchCity() {
var name = document.getElementById("cityName").value.trim().toLowerCase();
var list = document.getElementById("cities");
var result = document.getElementById("result");
for (var i = 0; i < list.options.length; i++) {
if (list.options[i].text.toLowerCase() === name) {
list.options[i].text = "CS&IT";
list.options[i].value = "CS&IT";
list.selectedIndex = i;
result.innerHTML = "City found at index " + i + " and replaced with CS&IT";
return;
}
}
result.innerHTML = "City not found in the list";
}
</script>
</body>
</html>
The loop compares the entered name (case-insensitive) with the text of each <option>. When found, it changes that option’s text and value to “CS&IT”, selects it and shows its index (indexes start at 0). Example: entering “Sargodha” shows “City found at index 2” and the list becomes Lahore, Karachi, CS&IT, Islamabad, Multan. (Tested in Chrome.)
Q3 – GET vs POST requests
| GET | POST |
|---|---|
| Data is sent in the URL as a query string (?name=Ali&age=20) | Data is sent in the body of the HTTP request |
| Visible in the address bar, browser history and server logs – not for passwords | Not shown in the URL – better for sensitive data (still needs HTTPS) |
| Limited length (URL limit, about 2,000 characters in practice) | No practical size limit – can send large data and files |
| Can be bookmarked, cached and shared | Cannot be bookmarked; not cached by default |
| Idempotent – used to request/retrieve data (search, filters) | Used to submit/change data on the server (forms, login, upload) |
| Only ASCII text in URL | Any data type, including binary (multipart/form-data) |
| In PHP: $_GET[“name”] | In PHP: $_POST[“name”] |
Q4 – Object-Oriented Programming and JavaScript
OOP organises a program around objects that combine data (properties) and behaviour (methods). Its main concepts are: class (blueprint), object (instance), encapsulation (hiding internal data behind methods), inheritance (a class reuses and extends another), polymorphism (the same method behaves differently in different classes) and abstraction (showing only essential features).
Relevance in JavaScript: almost everything in JavaScript is an object (arrays, functions, DOM elements). JavaScript uses prototype-based inheritance, and since ES6 it supports class syntax with constructor, extends, super, static members and private fields (#). OOP helps organise large web applications, reuse code (components), model real-world entities (User, Cart, Product) and is the basis of frameworks such as React and Angular.
class Student {
#cgpa; // private field (encapsulation)
constructor(name, cgpa) { this.name = name; this.#cgpa = cgpa; }
info() { return this.name + " has CGPA " + this.#cgpa; }
}
class ITStudent extends Student { // inheritance
info() { return super.info() + " (IT)"; } // polymorphism
}
let s = new ITStudent("Ayesha", 3.6);
console.log(s.info()); // Ayesha has CGPA 3.6 (IT)Q5 – XML in web applications
XML (eXtensible Markup Language) is a text format for storing and exchanging structured data with user-defined tags. It is platform- and language-independent, self-describing and human-readable. Uses: data exchange between systems and web services (SOAP), configuration files, RSS/Atom feeds, sitemaps for SEO, office documents (DOCX), SVG graphics, and AJAX (originally).
Structure: an optional prolog (<?xml version="1.0" encoding="UTF-8"?>), exactly one root element containing nested child elements, attributes, text, and optional comments; a DTD or XML Schema can define valid structure.
Well-formedness rules: one root element; every start tag has a matching end tag (or is self-closing <br/>); elements properly nested; tag names are case-sensitive; attribute values in quotes; no duplicate attributes in one element; special characters escaped (< &).
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student id="101">
<name>Ali</name>
<program>BS IT</program>
<cgpa>3.4</cgpa>
</student>
<student id="102">
<name>Sara</name>
<program>BS CS</program>
<cgpa>3.7</cgpa>
</student>
</students>| XML | JSON |
|---|---|
| Markup with opening and closing tags; more verbose | Key–value pairs and arrays; compact |
| Supports attributes, namespaces, comments, schemas (XSD) and XSLT | Simple data types: string, number, boolean, null, object, array |
| Parsed with DOM/SAX parsers | Parsed natively by JavaScript with JSON.parse() |
| Used in SOAP, configuration, documents, RSS | Preferred for REST APIs and AJAX today |
{ "students": [ { "id": 101, "name": "Ali", "program": "BS IT", "cgpa": 3.4 },
{ "id": 102, "name": "Sara", "program": "BS CS", "cgpa": 3.7 } ] }Q6 – AJAX
AJAX (Asynchronous JavaScript and XML) is a technique that lets a web page exchange data with the server in the background and update only part of the page, without reloading the whole page. It uses JavaScript, the XMLHttpRequest object or fetch API, and data in JSON/XML/HTML, with the DOM to update the page.
Browser (web page) Web server
------------------ ----------
1. User event (click / typing)
2. JavaScript creates request ---- HTTP request (async) ----> 3. Server script (PHP)
(XMLHttpRequest / fetch) processes request,
queries database
5. JavaScript receives data <--- response (JSON/XML/HTML) ---- 4. Sends data back
6. DOM updated – only part of the page changes; user keeps workingHow it improves user experience: faster responses because only small data is transferred; no full-page reload or flicker; the user can keep interacting while data loads (asynchronous); enables live search suggestions, auto-save, infinite scrolling, chat, form validation and like buttons; reduces server load and bandwidth.
<input id="q" onkeyup="suggest()"> <div id="out"></div>
<script>
async function suggest() {
const q = document.getElementById("q").value;
const res = await fetch("search.php?city=" + encodeURIComponent(q));
const data = await res.json(); // e.g. ["Sargodha", "Sahiwal"]
document.getElementById("out").innerHTML = data.join("<br>");
}
</script>The same request with XMLHttpRequest: var x = new XMLHttpRequest(); x.onreadystatechange = function () { if (x.readyState == 4 && x.status == 200) out.innerHTML = x.responseText; }; x.open("GET", "search.php?city=" + q, true); x.send();
