Web Design Module VI
Web Design Module VI
Introduction:
This module introduces the concepts and techniques needed to add dynamic and interactive
elements to websites. You will learn about scripting languages, specifically JavaScript, and how
it's used alongside HTML and CSS to create engaging user experiences. We'll cover JavaScript
fundamentals, how to control program flow, use functions, manipulate web page elements (DOM),
handle user events, and validate user input in forms.
• Key Characteristics:
• Examples: JavaScript (web client-side & server-side via Node.js), Python, Ruby, PHP,
Perl, Bash (shell script), PowerShell.
• Note: The line between scripting and general-purpose languages can sometimes be blurry.
These characteristics help identify a language's common usage as a scripting language.
• Concept: JavaScript is the primary scripting language used to add interactivity to websites.
It allows developers to create dynamic content, handle user actions, validate forms, make
asynchronous requests, and much more, transforming static HTML pages into engaging
experiences.
o Purpose: Primarily created to add interactivity to web pages on the client-side (in
the browser). It enables manipulation of the DOM (Document Object Model) and
the creation of responsive user interfaces.
o Core Function: Enables dynamic and interactive features on web pages (client-
side).
o Beyond the Browser: Used for server-side development (Node.js) and mobile app
development (React Native, etc.).
o Advantages of Learning: MUST for web developers, most popular language, easy
setup (runs in all browsers), enables beautiful/fast/interactive websites, opens
opportunities in mobile/desktop/game development, high job demand/pay, rich
ecosystem of tools.
o Object-Centered Script Language: Has built-in objects (like the window object).
Supports object-oriented features like polymorphism.
o Client Edge Technology: Runs primarily in the user's web browser (the client),
allowing control over content rendering and interaction without constant server
communication.
o If and Else Statement: Supports conditional logic to execute different code paths
based on conditions.
o Back-end Data Loading (AJAX): Fetching data from the server without reloading
the page.
o Steps:
4. Create HTML File: Create the main .html file for your webpage.
6. Start Coding & Testing: Write JS code, open the HTML file in the
browser, use browser developer tools (F12) for debugging.
o Tools:
▪ Example:
<body>
<h1>JavaScript Tutorials</h1>
<script>
</body>
o External Script File: Writing JavaScript code in a separate .js file and linking it
using the src attribute of the <script> tag.
o Multiple Scripts: An HTML page can contain multiple <script> tags, executed in
the order they appear.
• Concept: This unit focuses on using JavaScript to transform static web pages into
dynamic, interactive experiences. It covers the core language features needed to respond
to user actions and manipulate page content. JavaScript is the key technology for client-
side programming, executing within the user's browser to update content, validate forms,
create animations, and more, without needing to reload the entire page.
• 2.2.1 Variables, Data Types, and Operators: (Covered in detail in Unit 1, Section 1.2 -
review these concepts: let, const, primitive types
like Number, String, Boolean, Null, Undefined, structural types like Object, Array, and
operators like arithmetic, comparison, logical, assignment, ternary).
• 2.1.1.2 Comments (Revisiting): Essential for explaining code. Single-line (//) and Multi-
line (/* ... */). Can be used to temporarily disable code for testing.
o Example:
/* Multi-line
comment */
o Whitespace: JavaScript largely ignores extra spaces and tabs, use them for
readability.
▪ Example: if (score > 90) { grade = 'A'; } else if (score > 80) { grade = 'B'; }
else { grade = 'C'; }
o Note: Curly braces {} optional for single-statement blocks but recommended for
clarity.
o for loop: Executes a block a specific number of times. Syntax: for (initializer;
condition; iteration) { ... }.
▪ Example (basic): for (let i = 0; i < 5; i++) { console.log(i); }
▪ Example (array): var arr = [10, 20, 30]; for (var i = 0; i < arr.length; i++) {
console.log(arr[i]); }
o continue: Skips the rest of the current loop iteration and proceeds to the next one.
o try...catch...finally block:
▪ Example:
try {
console.log(result);
} catch (error) {
} finally {
console.log("Execution finished.");
}
o throw statement: Used to create custom errors. Can throw strings, numbers,
booleans, or objects.
• Concept: Reusable blocks of code that perform specific tasks. Key for organization and
reducing repetition. Statements often start with a keyword like function.
o Calling (Invoking): Using the function name followed by parentheses (), passing
arguments if needed.
▪ Example: greet("Abebe");
o Example (with block): let add = (a, b) => { let sum = a + b; return sum; };
o this Behavior: Arrow functions inherit this from the surrounding (lexical) scope,
unlike regular functions where this depends on how the function is called.
o Return Value: Functions use the return keyword to send a value back. If return is
omitted or used without a value, the function returns undefined. Functions can
return any data type, including other functions.
• (Implied) String Review (Covered in 2.2): Review string literals, template strings,
accessing characters, concatenation, String objects vs literals, comparison methods.
• Concept: JavaScript interacts with the HTML structure (DOM) to make pages dynamic.
Event handling allows JS to respond to user actions.
• DOM (Document Object Model): A tree-like representation of the HTML page. JS can
access nodes (elements, text, attributes) and modify them.
• Event Handling: Executing JS code in response to events like clicks (onclick), page loads
(onload), key presses, mouse movements, form submissions (onsubmit), input changes
(onchange, oninput).
• Importance: These two concepts combined allow for creating truly interactive web
applications.
o Removing Elements: pop() (end), shift() (start). Middle elements require creating
new arrays (e.g., using filter).
o Assigning Events via DOM: Using JavaScript to attach functions to element event
properties (e.g., element.onclick = functionName;).
▪ Example: document.getElementById("myBtn").onclick = displayDate;
o Note: Modern approach uses addEventListener() (not covered in detail in this PDF
section).
Unit 3: VALIDATING USER INPUT
o Applies to: Text fields, checkboxes, radio buttons, dropdowns, file uploads, etc.
o Concept: Specifically validating data entered into web forms before submission.
o Methods: