BIT251 · TU past paper
Web Technology I 2080 question paper
The complete TU 2080 exam paper for Web Technology I (BIT251), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- 110 marksHTML head and body tagsHideAnswer
Define HTML head and body tags. Write HTML script to display following output. The title of the page should be 'BIT Web Tech'.[10]
HTML Head and Body Tags
Definition
<head>TagThe
<head>tag is a container element that holds meta-information about the HTML document. The content inside the<head>tag is not displayed directly on the web page. It contains elements such as:<title>- defines the title of the page (shown in browser tab)<meta>- provides metadata like charset, author, description<link>- links external stylesheets<style>- contains internal CSS<script>- contains or links JavaScript
Syntax:
<head> <!-- meta information goes here --> </head>
<body>TagThe
<body>tag defines the main content of the HTML document that is visible to the user in the browser window. It contains all the displayable content such as:- Headings, paragraphs, images, links, tables, lists, forms, etc.
Syntax:
<body> <!-- visible content goes here --> </body>
HTML Script
Note: Since no image of the required output was provided, the following is a commonly expected output for this type of question in TU BScCSIT/BIT exams, featuring a heading, a table, and a list. Adjust content if your question had a specific screenshot.
<!DOCTYPE html> <html> <head> <title>BIT Web Tech</title> </head> <body bgcolor="lightblue"> <h1 align="center">Welcome to BIT Web Tech</h1> <hr> <h2>Course Information</h2> <table border="1" cellpadding="5" cellspacing="0"> <tr bgcolor="yellow"> <th>S.N.</th> <th>Course Name</th> <th>Credit Hour</th> </tr> <tr> <td>1</td> <td>Web Technology</td> <td>3</td> </tr> <tr> <td>2</td> <td>Database Management</td> <td>3</td> </tr> <tr> <td>3</td> <td>Programming in C</td> <td>3</td> </tr> </table> <h2>Key Features</h2> <ul> <li>HTML and CSS</li> <li>JavaScript</li> <li>PHP and MySQL</li> </ul> <h2>Semester List</h2> <ol> <li>First Semester</li> <li>Second Semester</li> <li>Third Semester</li> </ol> <hr> <p align="center"> <b>Contact us at:</b> <a href="mailto:[email protected]">[email protected]</a> </p> </body> </html>
Expected Browser Output
Element Description Browser Tab Shows BIT Web Tech Page Heading "Welcome to BIT Web Tech" centered Table Course information with border Unordered List Key features with bullet points Ordered List Semester list with numbers Footer Contact email as hyperlink
Summary Table of Head vs Body
Feature <head><body>Visibility Not visible to user Visible to user Contains Title, meta, style, script Text, images, tables, forms Purpose Document information Document content Required Yes Yes - 210 marksInline internal and external CSS methodsHideAnswer
How inline, internal, and external CSS are used in an HTML document. Illustrate with examples. Your CSS should include at least one class selector and id selector.[10]
CSS (Cascading Style Sheets) can be applied to an HTML document in three ways: Method Location Attribute/Tag Used -------------------------------------- Inline Inside the HTML element style attribute Internal Inside the <head section <st...
- 310 marksForm validation concept and purposeHideAnswer
Create an HTML form for signup. The form should contain form elements for username, password, email, country, gender, and hobbies. The username should be at least of 8 length, password should be of 6 length having at least one digit. The username and password should be present. The email should be valid. The country field in dropdown should be selected. The gender and hobbies in radio and checkboxes should also be checked respectively. Now write JavaScript function to validate the form as per mentioned.[10]
HTML Form with JavaScript Validation
Complete Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Signup Form</title> <style> body { font-family: Arial, sans-serif; max-width: 500px; margin: 40px auto; padding: 20px; border: 1px solid #ccc; border-radius: 8px; } h2 { text-align: center; color: #333; } .form-group { margin-bottom: 15px; } label { display: block; font-weight: bold; margin-bottom: 5px; } input[type="text"], input[type="password"], input[type="email"], select { width: 100%; padding: 8px; box-sizing: border-box; border: 1px solid #aaa; border-radius: 4px; } .error { color: red; font-size: 13px; margin-top: 4px; } input[type="submit"] { width: 100%; padding: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; } input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <h2>Signup Form</h2> <form name="signupForm" onsubmit="return validateForm()"> <!-- Username --> <div class="form-group"> <label for="username">Username:</label> <input type="text" id="username" name="username" placeholder="Enter username"> <span class="error" id="usernameError"></span> </div> <!-- Password --> <div class="form-group"> <label for="password">Password:</label> <input type="password" id="password" name="password" placeholder="Enter password"> <span class="error" id="passwordError"></span> </div> <!-- Email --> <div class="form-group"> <label for="email">Email:</label> <input type="email" id="email" name="email" placeholder="Enter email"> <span class="error" id="emailError"></span> </div> <!-- Country --> <div class="form-group"> <label for="country">Country:</label> <select id="country" name="country"> <option value="">-- Select Country --</option> <option value="nepal">Nepal</option> <option value="india">India</option> <option value="usa">USA</option> <option value="uk">UK</option> <option value="australia">Australia</option> </select> <span class="error" id="countryError"></span> </div> <!-- Gender --> <div class="form-group"> <label>Gender:</label> <input type="radio" name="gender" value="male"> Male <input type="radio" name="gender" value="female"> Female <input type="radio" name="gender" value="other"> Other <span class="error" id="genderError"></span> </div> <!-- Hobbies --> <div class="form-group"> <label>Hobbies:</label> <input type="checkbox" name="hobbies" value="reading"> Reading <input type="checkbox" name="hobbies" value="gaming"> Gaming <input type="checkbox" name="hobbies" value="travelling"> Travelling <input type="checkbox" name="hobbies" value="cooking"> Cooking <span class="error" id="hobbiesError"></span> </div> <!-- Submit --> <div class="form-group"> <input type="submit" value="Sign Up"> </div> </form> <script> function validateForm() { // Clear all previous error messages var errorIds = [ "usernameError", "passwordError", "emailError", "countryError", "genderError", "hobbiesError" ]; for (var i = 0; i < errorIds.length; i++) { document.getElementById(errorIds[i]).innerText = ""; } var isValid = true; // ---- 1. Username Validation ---- var username = document.getElementById("username").value.trim(); if (username === "") { document.getElementById("usernameError").innerText = "Username is required."; isValid = false; } else if (username.length < 8) { document.getElementById("usernameError").innerText = "Username must be at least 8 characters long."; isValid = false; } // ---- 2. Password Validation ---- var password = document.getElementById("password").value.trim(); var hasDigit = /\d/; // Regular expression to check for at least one digit if (password === "") { document.getElementById("passwordError").innerText = "Password is required."; isValid = false; } else if (password.length < 6) { document.getElementById("passwordError").innerText = "Password must be at least 6 characters long."; isValid = false; } else if (!hasDigit.test(password)) { document.getElementById("passwordError").innerText = "Password must contain at least one digit."; isValid = false; } // ---- 3. Email Validation ---- var email = document.getElementById("email").value.trim(); var emailPattern = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; if (email === "") { document.getElementById("emailError").innerText = "Email is required."; isValid = false; } else if (!emailPattern.test(email)) { document.getElementById("emailError").innerText = "Please enter a valid email address."; isValid = false; } // ---- 4. Country Validation (dropdown) ---- var country = document.getElementById("country").value; if (country === "") { document.getElementById("countryError").innerText = "Please select a country."; isValid = false; } // ---- 5. Gender Validation (radio buttons) ---- var genders = document.getElementsByName("gender"); var genderChosen = false; for (var g = 0; g < genders.length; g++) { if (genders[g].checked) { genderChosen = true; break; } } if (!genderChosen) { document.getElementById("genderError").innerText = "Please select your gender."; isValid = false; } // ---- 6. Hobbies Validation (checkboxes) ---- var hobbies = document.getElementsByName("hobbies"); var hobbyCount = 0; for (var h = 0; h < hobbies.length; h++) { if (hobbies[h].checked) { hobbyCount++; } } if (hobbyCount === 0) { document.getElementById("hobbiesError").innerText = "Please select at least one hobby."; isValid = false; } // ---- Final result ---- if (isValid) { alert("Signup successful."); } // false prevents submission, true allows it return isValid; } </script> </body> </html>
How Each Element is Validated
Element Type How the value is read Rule Username Text box getElementById("username").valueRequired, at least 8 characters Password Password box getElementById("password").valueRequired, at least 6 characters, must contain a digit Email Email box getElementById("email").valueRequired, must match the email pattern Country Dropdown getElementById("country").valueMust not be the empty placeholder option Gender Radio group getElementsByName("gender")Exactly one button must be checked Hobbies Checkbox group getElementsByName("hobbies")At least one box must be checked Radio buttons and checkboxes share a
namerather than anid, which is why they are read withgetElementsByName()and scanned in a loop, while single-valued controls are read directly byid.
Conclusion
The function clears the old messages first, then tests every control and records failures in a single
isValidflag instead of returning early, so the user sees all the problems in one pass. Returningfalsefromonsubmitcancels the submission. This client-side check gives instant feedback, but the same rules must be repeated on the server because JavaScript can be disabled or bypassed. - 45 marksHTTP request and responseHideAnswer
Describe HTTP Request and Response. [5]
HTTP is an application-layer protocol used for communication between a client (usually a web browser) and a server on the World Wide Web. It follows a simple request-response model. --- An HTTP request is a message sent by the client to ...
- 55 marksXMLHttpRequest objectHideAnswer
What is XMLHttpRequest Object? Write AJAX script to demonstrate use of XMLHttpRequest Object. [5]
The XMLHttpRequest (XHR) Object is a built-in browser API object that allows web pages to make asynchronous HTTP requests to a server without reloading the entire page. It is the core component of AJAX (Asynchronous JavaScript and XML) t...
- 65 marksHTML form events onchange onfocusHideAnswer
What are HTML form events? Write HTML script that prints some texts during onchange and onfocus event of some form elements. [5]
HTML Form Events
Definition
HTML form events are events that are triggered by user interactions with HTML form elements such as input fields, text areas, checkboxes, dropdown menus, and buttons. These events allow JavaScript to respond dynamically when a user interacts with form elements.
Common HTML Form Events
Event Description onchangeFires when the value of an element is changed and the element loses focus onfocusFires when an element receives focus (user clicks or tabs into it) onblurFires when an element loses focus onsubmitFires when a form is submitted onresetFires when a form is reset oninputFires when the value of an element changes (immediately)
HTML Script Example
<!DOCTYPE html> <html> <head> <title>HTML Form Events</title> </head> <body> <h2>HTML Form Events Demo</h2> <form> <!-- onfocus event on text input --> <label>Name:</label> <input type="text" id="nameField" onfocus="document.getElementById('msg1').innerHTML = 'Name field is now focused! Please enter your name.'" placeholder="Enter your name" /> <!-- onchange event on text input --> <label>Email:</label> <input type="text" id="emailField" onchange="document.getElementById('msg2').innerHTML = 'Email has been changed to: ' + this.value" onfocus="document.getElementById('msg1').innerHTML = 'Email field is now focused! Please enter your email.'" placeholder="Enter your email" /> <!-- onchange event on dropdown --> <label>Select Course:</label> <select id="courseSelect" onchange="document.getElementById('msg3').innerHTML = 'You selected: ' + this.value" onfocus="document.getElementById('msg1').innerHTML = 'Dropdown is focused! Please select a course.'" > <option value="">-- Choose --</option> <option value="CSIT">BSc CSIT</option> <option value="BCA">BCA</option> <option value="BIT">BIT</option> </select> </form> <!-- Output messages --> <p id="msg1" style="color: blue;"></p> <p id="msg2" style="color: green;"></p> <p id="msg3" style="color: red;"></p> </body> </html>
Output Explanation
-
When the user clicks on the Name field,
onfocusfires and prints:"Name field is now focused! Please enter your name." -
When the user changes the Email field and moves away,
onchangefires and prints:"Email has been changed to: [email protected]" -
When the user selects a course from the dropdown,
onchangefires and prints:"You selected: CSIT"
Note:
onchangefires after the value is changed and the element loses focus, whileonfocusfires immediately when the element gains focus. -
- 75 marksCSS positioning static relative absolute fHideAnswer
Write internal CSS to illustrate the static, relative, and fixed position property of an HTML element. [5]
The CSS position property controls how an element is placed in the document. The three key values are: Value Description -------------------- static Default positioning; element flows in normal document order relative Positioned relative...
- 85 marksFigure tag with captionsHideAnswer
Write HTML script to markup photo in an HTML document using figure tag. The source path of the photo is D:\BIT\CAMPUS.JPEG. Set the alternate text to 'BIT'. The caption of the figure should be 'This is the BIT Campus'. [5]
The <figure tag in HTML is used to mark up self-contained content such as images, diagrams, or photos. The <figcaption tag is used inside <figure to provide a caption for the content. --- --- Tag / Attribute Purpose ------ <figure Define...
- 95 marksXQuery language and expressionsHideAnswer
What is Xquery? Given following XML, write an XQuery to retrieve the title of movies having budget greater than 500. Write result of the XQuery expression. [5]
XQuery is a query and functional language designed to query and transform XML data. It is to XML what SQL is to relational databases. XQuery is built on XPath expressions and can extract, filter, and restructure data from XML documents. ...
- 105 marksXML definition and purposeHideAnswer
What is the use of XML? Why is it called extensible, justify with example. [5]
XML: Uses and Extensibility
What is XML?
XML (eXtensible Markup Language) is a markup language designed to store, transport, and describe data in a structured, human-readable, and machine-readable format. It is a W3C recommended standard.
Uses of XML
Use Description Data Storage Stores structured data in plain text files (e.g., configuration files) Data Exchange Transfers data between different systems and platforms (e.g., web services, APIs) Web Development Used in technologies like XHTML, RSS, SOAP, and AJAX Database Communication Acts as a medium to exchange data between databases Document Representation Represents documents with complex structure (e.g., Microsoft Office .docx)Configuration Files Many applications use XML for configuration (e.g., web.xmlin Java)
Why is XML Called "Extensible"?
XML is called extensible because:
Unlike HTML, which has a fixed, predefined set of tags, XML allows users to define their own custom tags according to their specific needs.
There is no fixed vocabulary in XML. You can create any tag name that is meaningful to your application. This ability to extend and define new markup makes it "extensible."
Justification with Example
HTML (NOT extensible - fixed tags only):
<p>John</p> <b>Engineer</b>You cannot create
<student>or<rollno>in HTML.
XML (Extensible - user-defined tags):
Suppose a school wants to store student data. They can define their own tags:
<?xml version="1.0" encoding="UTF-8"?> <school> <student> <rollno>101</rollno> <name>Ram Sharma</name> <faculty>BSc CSIT</faculty> <semester>5</semester> </student> <student> <rollno>102</rollno> <name>Sita Thapa</name> <faculty>BSc CSIT</faculty> <semester>5</semester> </student> </school>Now suppose a hospital needs to store patient data. They define completely different tags:
<?xml version="1.0" encoding="UTF-8"?> <hospital> <patient> <patientid>P001</patientid> <name>Hari Bahadur</name> <disease>Fever</disease> <doctor>Dr. Laxmi</doctor> </patient> </hospital>Key Observations:
- Tags like
<rollno>,<faculty>,<patient>,<disease>are not predefined anywhere. - The user created them based on their own requirements.
- Both examples are valid XML despite having completely different tag sets.
Summary
XML is called extensible because it does not restrict users to a fixed set of tags. Users can invent, define, and use their own tags to describe any kind of data, making XML flexible and adaptable to any domain or application.
- Tags like
- 115 marksDTD versus XSD comparisonHideAnswer
How DTD is different from XSD? [5]
Note: The reference notes did not contain this topic directly. The following answer is based on standard XML curriculum content appropriate for BSc CSIT. --- DTD is a set of rules/declarations that defines the structure and legal element...
- 125 marksException handling try catchHideAnswer
How exception handling is done in JavaScript? Write a JavaScript program that will handle an exception when an input number is divided by zero. [5]
Exception handling is a mechanism to handle runtime errors gracefully so that the normal flow of the program is not disrupted. JavaScript uses the try...catch...finally construct for exception handling. --- Keyword Purpose --------------...