CSC329 · TU past paper
Web Technology 2081 question paper
The complete TU 2081 exam paper for Web Technology (CSC329), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- Q1.10 marksSyntax Rules for creating XML documentHideAnswer
Describe the rules for creating XML document. Create a XML file with simple type and elements with attribute and nested elements. Write its equivalent XSD.[10]
- Q2.10 marksEvent Handling and Form ValidationHideAnswer
Create an HTML file containing form with textbox, select and radio button. Now write a javascript function for validating the form elements. Validate textbox for required, select field should have some value selected and radio button should be checked.[10]
- Q3.10 marksPHP FormsHideAnswer
Write a PHP program to create a form. Create an insertdb() method to insert the form values into a database table and display() to display the database table value.[10]
- Q4.5 marksTablesHideAnswer
Write a HTML script to create a table with three rows and three columns. The second row third column should contain a text 'TU' with link set to www.tu.edu.np. The height of second row should be set to 200px. [5]
- Q5.5 marksHTML EventsHideAnswer
What is onload event in HTML? Write an HTML script that displays alert message 'Hello Nepal' in onload event. [5]
Onload Event in HTML
Definition
The onload event is an event handler in HTML/JavaScript that is triggered automatically when a web page (or an element such as an image) has completely finished loading in the browser. It is commonly used with the
<body>tag.- It belongs to the category of Event Handlers -- JavaScript code placed inside HTML tags that execute when something happens.
- The basic syntax of an event handler is:
name_of_handler = "JavaScript code goes here"For the onload event specifically:
<body onload="JavaScript code or function call">The
onloadevent is useful for:- Displaying welcome messages when a page loads
- Initializing variables or functions automatically
- Checking cookies or browser information on page start
HTML Script: Display Alert 'Hello Nepal' on Onload Event
<html> <head> <title>Onload Event Example</title> <script type="text/javascript"> function showMessage() { alert("Hello Nepal"); } </script> </head> <body onload="showMessage()"> <h2>Welcome to Nepal!</h2> <p>This page demonstrates the onload event in HTML.</p> </body> </html>
Explanation of the Script
Part Description <script type="text/javascript">Defines the JavaScript block inside the <head>tagfunction showMessage()A JavaScript function that triggers an alert box alert("Hello Nepal")Displays a popup dialog with the message Hello Nepal <body onload="showMessage()">Calls showMessage()automatically when the page finishes loading
How It Works
- The browser loads the HTML page completely.
- As soon as the
<body>finishes loading, theonloadevent is fired. - The
showMessage()function is called automatically. - An alert box appears with the message "Hello Nepal".
- The user clicks OK and sees the rest of the page content.
Note: The
onloadevent handler follows the same event handling principle described in the curriculum: event handlers are placed inside HTML tags (not inside<script>tags) and execute JavaScript when a specific event occurs. - Q6.5 marksInserting CSSHideAnswer
How internal and external CSS differ from each other. Illustrate with example. [5]
- Q7.5 marksArraysHideAnswer
How can you define array in javascript? Create an array Fruit with its elements 'apple', 'banana', 'mango', 'grape' and print the array. [5]
- Q8.5 marksXML Style SheetsHideAnswer
How can you transform XML document into HTML using XSLT. Support your answer with an example. [5]
- Q9.5 marksFunctionsHideAnswer
Write a PHP function add that takes two arguments as an input and return their sum. [5]
- Q10.5 marksCookies and SessionsHideAnswer
Define cookie. Write a PHP program to create and retrieve a cookie. [5]
Cookie: Definition and PHP Program
Definition of Cookie
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. Cookies are used to identify users and store information between page requests. Examples of cookies include Name cookie, Date cookie, etc.
PHP can send and receive cookies.
PHP Program to Create and Retrieve a Cookie
Step 1: Create (Set) a Cookie
<?php // Setting a cookie // setcookie(name, value, expiry_time) $cookie_name = "username"; $cookie_value = "JohnDoe"; // Cookie expires in 1 day (time() + 86400 seconds) setcookie($cookie_name, $cookie_value, time() + 86400); echo "Cookie has been set successfully!"; ?>
Step 2: Retrieve (Read) a Cookie
<?php // Retrieving the cookie if (isset($_COOKIE["username"])) { echo "Cookie Found! "; echo "Username is: " . $_COOKIE["username"]; } else { echo "Cookie is not set."; } ?>
Complete Program (Create and Retrieve in One File)
<?php // Step 1: Create/Set the cookie $cookie_name = "username"; $cookie_value = "JohnDoe"; // setcookie must be called before any HTML output setcookie($cookie_name, $cookie_value, time() + 86400); // expires in 1 day ?> <!DOCTYPE html> <html> <head> <title>Cookie Example</title> </head> <body> <?php // Step 2: Retrieve the cookie if (isset($_COOKIE["username"])) { echo "<p>Cookie Name : username</p>"; echo "<p>Cookie Value : " . $_COOKIE["username"] . "</p>"; } else { echo "<p>Cookie is not set yet. Please refresh the page.</p>"; } ?> </body> </html>
Output
Cookie Name : username Cookie Value : JohnDoe
Key Points
Function / Variable Purpose setcookie()Creates/sets a cookie on the client's computer $_COOKIE[]Superglobal array used to retrieve cookie values isset()Checks whether the cookie exists before reading time() + 86400Sets expiry to 1 day (86400 seconds) from now Note:
setcookie()must be called before any HTML output, otherwise the cookie will not be set. - Q11.5 marksText Effects and shadowHideAnswer
What is text-overflow property in CSS? How can you use clip and ellipsis in text-overflow? [5]
- Q12.5 marksClient Server ArchitectureHideAnswer
Describe client server architecture with its types. [5]