Unit 1: HTML, DHTML and JavaScript exercises
Software Lab-VI (Web Technologies) notes · PTU syllabus (BSIT307)
On this page
Unit summary
This lab builds web pages with HTML, DHTML and JavaScript: formatting tags, ordered and unordered lists, tables, an admission form, frames, image maps, hyperlinks between pages, cascading style sheets, and JavaScript programs for comparing numbers, for loops, if and if-else statements, functions with arguments, and even/odd and prime checking.
After this unit you can
- Build pages with formatting tags, lists, tables and hyperlinks
- Design an admission form, frames and image maps
- Style pages with CSS
- Write JavaScript programs using conditions, loops and functions
PTU syllabus topics
- HTML formatting tags
- ordered and unordered lists
- table creation
- admission form design
- frame creation
- image maps
- hyperlinks between pages
- cascading style sheets
- JavaScript programs for number comparison
- for-loop implementation
- if and if-else statements
- functions with arguments
- even/odd checking
- prime number checking
Topic 1
Formatting tags, lists, tables and hyperlinks
Lab exercises combine formatting tags, lists, tables and links into complete pages.
| Exercise | Key tags |
|---|---|
| Book index page | <ol>, nested lists, <a> links to chapters |
| College letterhead | <h1>, <img>, <hr>, <address>, CSS for layout |
| In-page navigation | id attributes and <a href="#section"> |
| Formatted letter | <p>, <b>, <i>, <u>, <br>, alignment |
| Department timetable | <table>, <th>, colspan, rowspan, <caption> |
| Student bio-data | Table or definition list with photo |
Example
A college timetable page: use <table border="1"> with <th> for days, colspan for a double lab period, a heading with <h2>, and a link back to the home page.
Exam tip
Check every page in the browser and fix nesting errors — close tags in the reverse order they were opened.
Topic 2
Admission form
An admission form combines text boxes, radio buttons, checkboxes, a drop-down, a textarea and submit and reset buttons inside a form.
html<form action="submit.php" method="post">
<fieldset>
<legend>Admission Form — B.Sc IT</legend>
Name: <input type="text" name="name" required><br>
Email: <input type="email" name="email"><br>
Password: <input type="password" name="pwd"><br>
Gender: <input type="radio" name="g" value="M"> Male
<input type="radio" name="g" value="F"> Female<br>
Subjects: <input type="checkbox" name="s" value="Maths"> Maths
<input type="checkbox" name="s" value="CS"> Computer Science<br>
City: <select name="city"><option>Ludhiana</option><option>Jalandhar</option></select><br>
Address: <textarea name="addr" rows="3" cols="30"></textarea><br>
<input type="submit" value="Submit"> <input type="reset">
</fieldset>
</form>Example
Building the form: fields for name and email (text, email), gender (radio), course (select), subjects (checkbox), address (textarea), and Submit and Reset buttons, all grouped with fieldset and legend.
Exam tip
Use the label tag for every field so clicking the text selects the control.
Topic 3
Frames, image maps and media
HTML5 adds <audio> and <video> tags for media without plug-ins; <iframe> embeds another page or a video.
- Audio:
<audio src="song.mp3" controls></audio> - Video:
<video src="tour.mp4" width="480" controls></video> - Multi-frame page: a logo frame at the top, a menu on the left and content on the right — built with
<frameset>in old HTML, or with<iframe>and CSS layout today.
Example
Embedding media: <video src="tour.mp4" width="480" controls></video> shows a campus tour with play and pause buttons; an <iframe> embeds a Google Map of the college location.
Exam tip
Add the controls attribute so users can play and pause media.
Topic 4
Cascading style sheets
CSS uses selectors (element, class with ., id with #) and properties such as color, font-size, margin, padding, border and background.
html<link rel="stylesheet" href="hospital.css">cssbody { font-family: Arial, sans-serif; margin: 0; }
header { background: #0b6b3a; color: white; padding: 20px; }
nav a { color: white; margin-right: 15px; text-decoration: none; }
.card { border: 1px solid #ddd; border-radius: 8px; padding: 15px; }Example
Styling a hospital page: .doctor { border: 1px solid #ccc; padding: 10px; } styles every doctor card, and #emergency { color: red; font-weight: bold; } highlights the single emergency number.
Exam tip
Class (.) can be used on many elements; id (#) should be unique on a page.
Topic 5
JavaScript programs
html<script>
// Compare two numbers
function compare(a, b) {
if (a > b) return a + " is greater";
else if (b > a) return b + " is greater";
else return "Both are equal";
}
// For loop: multiplication table
function table(n) {
let out = "";
for (let i = 1; i <= 10; i++) out += n + " x " + i + " = " + n * i + "<br>";
document.getElementById("out").innerHTML = out;
}
// Even or odd
function evenOdd(n) { return n % 2 === 0 ? "Even" : "Odd"; }
// Prime check
function isPrime(n) {
if (n < 2) return false;
for (let i = 2; i * i <= n; i++) if (n % i === 0) return false;
return true;
}
alert(compare(12, 7) + ", 15 is " + evenOdd(15) + ", 29 prime? " + isPrime(29));
</script>Topic 6
JavaScript form validation
Form validation checks input in the browser before submission, giving instant feedback.
- 1
Read values
document.forms["reg"]
- 2
Check required fields
Not empty
- 3
Check formats
Email contains @ and a dot; phone has 10 digits
- 4
Check passwords
Length ≥ 8 and both entries match
- 5
Show errors
alert or a message next to the field
- 6
Return true or false
javascriptfunction validateReg() {
const f = document.forms["reg"];
if (!/^[0-9]{10}$/.test(f.phone.value)) { alert("Enter a 10-digit phone"); return false; }
if (f.pwd.value !== f.cpwd.value) { alert("Passwords do not match"); return false; }
return true;
}Exam tip
The final project — an institute website with department pages, tutorial links and validated forms — usually carries the most marks. Keep a consistent navigation bar and one external CSS file for all pages.
Example
Validating a form: if (document.forms["reg"]["phone"].value.length != 10) { alert("Enter a 10-digit phone number"); return false; } — with onsubmit="return validate()", the form is not submitted until the number is correct.
Exam tip
Return false from the validation function to stop the form from submitting.
Key terms
- DHTML
- HTML combined with CSS and JavaScript for dynamic pages
- fieldset
- Element grouping related form controls
- Image map
- Image with clickable regions
- External stylesheet
- CSS in a separate .css file
- Function argument
- Value passed to a function
Quick revision
- Formatting tags, lists, tables, hyperlinks.
- Form elements for an admission form.
- Frames and iframes; image maps with area.
- Inline, internal, external CSS.
- JavaScript: comparison, for loop, if-else, functions with arguments, even/odd, prime; validation.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Which tag groups form controls with a caption?
- Q2.Write HTML for a hyperlink opening in a new tab.
- Q3.How do you link an external CSS file?
- Q4.Write a JavaScript condition to test an even number.
- Q5.Why do we check divisors only up to √n for primes?
- Q6.What is DHTML?
Long-answer questions
- Q1.Create a web page using formatting tags, lists and tables.
- Q2.Design an admission form with all input types.
- Q3.Create an image map and pages linked with hyperlinks and frames.
- Q4.Write JavaScript programs for number comparison, multiplication table, even/odd and prime checking.
Stuck on this unit?
Message SBS on WhatsApp for help with Software Lab-VI (Web Technologies), or to ask about studying B.Sc IT at Synetic.
