WEB
WEB
TECHNOLOGIES
INDEX
1.
HTML
3. Link Tags
<a> : Anchor, used for hyperlinks.
Example:
<a href="https://www.example.com">Visit Example.com</a>
<link> : Defines the relationship between a document and an external
resource (most commonly used to
link to CSS stylesheets).
Example:
<link rel="stylesheet" href="styles.css">
4. Image Tag
<img> : Image.
Example:
<img src="image.jpg" alt="Description of the image">
5. Table Tags
<table> : Defines a table.
<tr> : Defines a row in a table.
<th> : Defines a header cell in a table.
<td> : Defines a cell in a table.
Example:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
6. Form Tags
<form> : Defines an HTML form for user input.
<input> : Input fields (text, checkbox, radio buttons, etc.).
<textarea> : Text area for multi-line text input.
<button>`: Button.
<select>`: Dropdown list.
<option>`: Options within a select element.
<label>`: Defines a label for an input element.
Example:
<form action="/submit" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message"></textarea><br>
<input type="checkbox" id="agree" name="agree">
<label for="agree">I agree to the terms and conditions.</label><br>
<input type="submit" value="Submit">
</form>
8. Sectioning Tags
<header> : Represents introductory content or a group of navigational
links.
<nav> : Defines a section with navigation links.
<main> : Represents the main content of the document.
<section> : Defines a section in a document.
<article> : Represents an independent piece of content that can be
syndicated.
<aside> : Represents content aside from the content it is placed in (like
sidebars).
<footer> : Defines a footer for a document or section.
Example:
<header>
<h1>Website Header</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>Article Title</h2>
<p>Article content...</p>
</article>
<aside>
<h3>Sidebar</h3>
<p>Content for the sidebar...</p>
</aside>
</main>
<footer>
<p>© 2024 Company Name. All rights reserved.</p>
</footer>
9. Interactive Tags
<button> : Button.
<input type="button"> : Button.
<input type="checkbox"> : Checkbox.
<input type="radio"> : Radio button.
<select> : Dropdown list.
<option> : Options within a select element.
<textarea> : Text area for multi-line text input.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Tags Example</title>
</head>
<body>
<form action="/submit" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message"></textarea><br>
<input type="checkbox" id="agree" name="agree">
<label for="agree">I agree to the terms and conditions.</label><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
2.
Rowspan and Colspan in HTML Table
In HTML, colspan and rowspan are attributes used within table elements
(<table>, <td>, and <th>) to specify how many columns or rows a table cell
should span, respectively.
Colspan
The colspan attribute specifies the number of columns a <td> or <th> element
should span. For example:
<table border="1">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td colspan="2">Spanning Cell</td>
</tr>
</table>
Rowspan
The rowspan attribute specifies the number of rows a <td> or <th> element
should span. For example:
<table border="1">
<tr>
<td>Cell 1</td>
<td rowspan="2">Spanning Cell</td>
</tr>
<tr>
<td>Cell 2</td>
</tr>
</table>
<h2>Student Information</h2>
</body>
</html>
Output :-
3.
CSS
4.
JavaScript
Features:
Client-Side Scripting: JavaScript code runs on the client's web browser,
enabling dynamic manipulation of HTML and CSS.
Event-Driven Programming: JavaScript allows developers to respond to
user actions and events such as clicks, form submissions, and mouse
movements.
Asynchronous Programming: JavaScript supports asynchronous
operations using callbacks, promises, and async/await, facilitating non-
blocking I/O operations.
DOM Manipulation: JavaScript can interact with the Document Object
Model (DOM) of a web page, allowing developers to dynamically modify
page content and structure.
Cross-Platform Compatibility: JavaScript is supported by all major web
browsers and can be executed on various operating systems and devices.
Extensibility: JavaScript can be extended through libraries and
frameworks such as jQuery, React, Angular, and Vue.js, which provide
additional functionalities and simplify development.
Applications:
Web Development: JavaScript is widely used to create interactive and
dynamic web applications, including single-page applications (SPAs) and
progressive web apps (PWAs).
Game Development: JavaScript, along with HTML5 canvas and WebGL, is
used to develop browser-based games and interactive experiences.
Server-Side Development: With Node.js, JavaScript can be used for
server-side programming, enabling fullstack JavaScript development.
Mobile App Development: JavaScript frameworks like React Native and
Ionic allow developers to build cross-platform mobile apps using web
technologies.
Desktop App Development: Frameworks like Electron enable developers
to create desktop applications using JavaScript, HTML, and CSS.
Data Visualization: JavaScript libraries like D3.js and Chart.js are used to
create interactive data visualizations and charts on the web.
5.
Javascript from
JAVASCRIPT CODE:
document.getElementById("myForm").addEventListener("submit", function(event) {
// Prevent form submission
event.preventDefault();
// Get form values
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var message = document.getElementById("message").value;
// Validate form inputs (simple validation)
if (name === "" || email === "" || message === "") {
document.getElementById("messageBox").innerHTML = "Please fill in all fields.";
return;
}
// Submit form data (simulated)
document.getElementById("messageBox").innerHTML = "Name: " + name + "<br>Email: " +
email + "<br>Message: " + message;
});
6.
XML
- Tags : Like HTML, XML uses tags to define elements. However, in XML, tags
are user-defined and can be named anything.
- Attributes : XML elements can have attributes just like HTML elements,
providing additional information about the element.
- Nesting : XML elements can be nested within each other to represent
hierarchical data structures.
- Well-formedness : XML documents must adhere to certain syntax rules to be
considered well-formed, such as having a single root element and properly
nested elements.
Here's a simple example of an XML document:
```xml
<bookstore>
<book category="fiction">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="non-fiction">
20
<title lang="en">The Elements of Style</title>
<author>William Strunk Jr.</author>
<year>1918</year>
<price>9.95</price>
</book>
</bookstore>
```
In this example, `<bookstore>` is the root element, and it contains two
`<book>` elements, each representing information about a book. Each `<book>`
element has child elements like `<title>`, `<author>`, `<year>`, and `<price>`, as
well as attributes like `category` and `lang`.
XML can interact with HTML:
1. Displaying XML data in HTML:
You can use JavaScript or server-side languages like PHP to fetch XML data and
dynamically generate
HTML content to display it. Here's a simple example using JavaScript:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>XML to HTML</title>
</head>
<body>
<div id="books"></div>
<script>
// XML data
var xmlData = `
<bookstore>
<book category="fiction">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="non-fiction">
<title lang="en">The Elements of Style</title>
<author>William Strunk Jr.</author>
<year>1918</year>
<price>9.95</price>
</book>
</bookstore>`;
// Parse XML string to XML document
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlData, "text/xml");
// Generate HTML content from XML
var booksDiv = document.getElementById("books");
var books = xmlDoc.getElementsByTagName("book");
for (var i = 0; i < books.length; i++) {
var book = books[i];
var title = book.getElementsByTagName("title")[0].textContent;
var author = book.getElementsByTagName("author")[0].textContent;
var year = book.getElementsByTagName("year")[0].textContent;
var price = book.getElementsByTagName("price")[0].textContent;
var bookInfo = `
<div>
<h2>${title}</h2>
<p>Author: ${author}</p>
<p>Year: ${year}</p>
<p>Price: ${price}</p>
</div>`;
booksDiv.innerHTML += bookInfo;
}
</script>
</body>
</html>
7.
PHP
if-elseif-else statement
<?php
$grade = 85;
if ($grade >= 90) {
echo "You got an A.";
} elseif ($grade >= 80) {
echo "You got a B.";
} elseif ($grade >= 70) {
echo "You got a C.";
} else {
echo "You need to improve your grade.";
}
echo "<br>";
?>
Switch statement
<?php
$day = "Monday";
switch ($day) {
32
case "Monday":
echo "Today is Monday.";
break;
case "Tuesday":
echo "Today is Tuesday.";
break;
case "Wednesday":
echo "Today is Wednesday.";
break;
case "Thursday":
echo "Today is Thursday.";
break;
case "Friday":
echo "Today is Friday.";
break;
default:
echo "It's a weekend day.";
}
?>
Loops in PHP
for Loop
for (initialization; condition; increment/decrement)
{ // code to be executed }
The for loop executes a block of code a specified number of times.
Example:
phpCopy code
for ($i = 0; $i < 5; $i++)
{ echo "The number is: $i <br>"; }
While Loop
while (condition)
{ // code to be executed // increment/decrement }
The while loop executes a block of code as long as the specified
condition is true.
Example:
$num = 1;
while ($num <= 5)
{ echo "The number is: $num <br>"; $num++; }
3. do-while Loop:
do { // code to be executed // increment/decrement
}while (condition);
The do-while loop is similar to the while loop, but the condition is evaluated after
executing the block of code,
meaning the code inside the loop will always execute at least once.
Example:
phpCopy code
$num = 1;
do
{
echo "The number is: $num <br>"; $num++;
} while ($num <= 5);
foreach Loop
foreach ($array as $value)
{ // code to be executed }
The foreach loop is used to loop through arrays. It iterates over each
key/value pair in an array.
Example:
$colors = array("Red", "Green", "Blue");
foreach ($colors as $color) {
echo "$color <br>";
}
8.
Forms in PHP