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
- 1Plan the layout
Header, content, footer
- 2Write the HTML
Tables, lists, forms
- 3Style with CSS
External stylesheet
- 4Add JavaScript
Validation, calculations
- 5Test in the browser
Check every link and input
Topic 1
Formatting tags, lists, tables and hyperlinks
| 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 |
Topic 2
Admission 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>Topic 3
Frames, image maps and media
- 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.
Topic 4
Cascading style sheets
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; }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
- 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.
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.
