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.
- 110 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]
The following rules must be followed: Rule 1: Every XML document must have exactly one Root Element All XML content must be enclosed within a single root element. Rule 2: All Tags Must Be Closed Every opening tag must have a correspondin...
- 210 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]
--- - The <form tag uses the onsubmit event handler to call validateForm(). - Returning false from the function prevents form submission if validation fails. - Checks that the textbox is not empty (required field). - The default option h...
- 310 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]
--- Before running the program, create the table in MySQL: --- Part Description ------ mysqliconnect() Creates connection to MySQL using procedural approach insertdb(
- 45 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]
--- Element / Attribute Purpose ------ <table border="1" Creates the table with a visible border <tr Defines each table row <td Defines each table data cell (column) <tr height="200px" Sets the height of the second row to 200px <a href="...
- 55 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. - 65 marksInserting CSSHideAnswer
How internal and external CSS differ from each other. Illustrate with example. [5]
CSS (Cascading Style Sheets) is used to control the presentation and layout of HTML elements. It can be applied in different ways, two of which are Internal CSS and External CSS. --- - Internal CSS is written inside the HTML document its...
- 75 marksArraysHideAnswer
How can you define array in javascript? Create an array Fruit with its elements 'apple', 'banana', 'mango', 'grape' and print the array. [5]
As per the notes, an array is a special variable which can hold more than one value at a time. We can access the values of an array by referring to an index number, and the index of an array starts with 0. Arrays are special types of obj...
- 85 marksXML Style SheetsHideAnswer
How can you transform XML document into HTML using XSLT. Support your answer with an example. [5]
XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other formats such as HTML for web pages, plain text, or other XML documents. The original document is not changed; rather, a new doc...
- 95 marksFunctionsHideAnswer
Write a PHP function add that takes two arguments as an input and return their sum. [5]
Based on the PHP Functions and Function Arguments concepts A PHP function is declared using the function keyword, and arguments are passed inside the parentheses separated by commas. --- --- --- Part Description ------ function add(...) ...
- 105 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. - 115 marksText Effects and shadowHideAnswer
What is text-overflow property in CSS? How can you use clip and ellipsis in text-overflow? [5]
The CSS text-overflow property specifies how overflowed content that is not displayed should be signaled (viewed) to the user. When text is too long to fit within its container, this property controls how the overflow is indicated to the...
- 125 marksClient Server ArchitectureHideAnswer
Describe client server architecture with its types. [5]
Client-Server architecture is a computing model in which a client requests a server for resources. The server hosts, delivers, and manages most of the resources and services to be consumed by the client. It has one or more clients connec...