Web Development Basics: HTML, CSS, JavaScript, PHP, and XML
Q1. Explain <textarea> Tag
The <textarea> tag in HTML is used to create a multiline text input field within a form. It allows users to enter and edit text over multiple lines. The content of the <textarea> element is the initial text displayed in the input field.
<textarea>Initial text goes here</textarea>
In this example, the <textarea> element creates a text input field labeled “Description” with an initial text value and a size of 4 rows and 50 columns. Users can expand or contract the input field vertically or horizontally based on the specified number of rows and columns. When the form is submitted, the content entered into the <textarea> is sent to the server as part of the form data. On the server side, you can then process and handle the user’s input.
Q2. Explain <form>. Explain Action and Method Attributes
A <form> element is used to create an interactive form that allows users to input and submit data.
<label for="username">Username:</label>
The action attribute specifies the URL or the script that will process the form data when it is submitted. The method attribute specifies the HTTP method used when submitting the form. The two primary methods are “GET” and “POST.”
Method=”get”:
- Appends form data to the URL in the form of query parameters.
- Suitable for simple data retrieval and when the form data doesn’t involve sensitive information.
Method=”post”:
- Sends form data in the request body, which is not visible in the URL.
- Suitable for submitting sensitive information, such as passwords.
Q3. What is DNS? Explain Domain and Subdomain with Examples
DNS, or Domain Name System, is a hierarchical and decentralized naming system for computers. Its primary function is to translate human-readable domain names into IP addresses, which are used by computers to identify each other on the network.
Q4. Write a Note on XML Namespaces
XML namespaces are a mechanism in XML that allows the creation of uniquely named elements and attributes, preventing naming conflicts in document structures. They enable the combination of different XML vocabularies within a single document, promoting interoperability. Namespaces are declared using the “xmlns” attribute, associating a prefix with a Uniform Resource Identifier (URI). This URI acts as a globally unique identifier, ensuring the distinction of elements and attributes. By using namespaces, developers can integrate diverse data sources and standards seamlessly, enhancing the extensibility and flexibility of XML documents in various applications, including web services, data interchange, and configuration files.
Q5. Explain Four Types of Selectors in CSS. Give Examples
1. Type Selector
Selects all instances of a specified HTML element type. Example: p { color: blue; }
2. Class Selector
Selects all elements with a specified class attribute. Example: .highlight { background-color: yellow; }
3. ID Selector
Selects a single element with a specified ID attribute. Example: #header { font-size: 24px; }
4. Descendant Selector
Selects an element that is a descendant of another specified element. Example: .container span { font-weight: bold; }
Q6. Describe Client-Server Architecture
Client-server architecture is a type of distributed system that consists of clients and servers. The server is responsible for hosting, managing, and delivering services to clients. Clients are connected to the server and communicate with it over the internet using a computer network. So when a client needs a service, it sends a request to the server, which processes the request and sends a response back to the client. It begins when a client requests data from the server, and the server processes the request by querying a database for relevant data. The database then returns the queried data to the server, which processes it and sends it back to the client. Clients cannot communicate directly with each other.
Q7. Need for an Internet Connection
- Like the telephone system, the internet provides connection.
- It is an essential medium for communication and interconnecting with people worldwide.
- The need to publish and share information has fueled the rapid growth of the web.
Q8. Explain Internet Connectivity
Internet connectivity refers to the ability of devices and networks to establish communication and exchange data over a global network of interconnected computers. This connectivity is made possible through a complex infrastructure involving various technologies.
At its core, the internet relies on the IP (Internet Protocol). Devices are assigned unique IP addresses that facilitate their identification and communication. Data packets are routed through routers and switches across the internet, using protocols like TCP and UDP.
Users access the internet through ISP’s (Internet Service Providers) via wired or wireless connections. Technologies like broadband, fiber optics, and mobile networks enable high-speed data transmission. DNS (Domain Name System) translates user-friendly domain names into IP addresses, facilitating navigation.
The internet’s decentralized nature allows for global connectivity, enabling communication, information sharing, e-commerce, social interaction, and many more.
Q9. Advantages of Client-Server Architecture
The client-server architecture has several benefits, including:
Centralized Management
Client-server architecture involves storing and managing data in one central location. This allows for complete control over processes and activities and makes it easy to share resources and data across different platforms. Users also have the authority to access any file stored in the central storage at any time.
Flexibility
The data passed between the client and server and the services provided by the server are entirely at the discretion of the programmer. As a result, there are many ways to use the client-server architecture to solve future problems. Additionally, this architecture can be easily combined with other types of architectures on the client or server sides.
Extensibility
The system can be updated based on changes in functional and non-functional requirements without altering the client-server architecture or disrupting service.
Transparency
Clients only make requests to the server with their input data, so they don’t see how the server will handle the request. It may seem like a single, central server to the user.
Scalability
The client-server architecture is capable of adding or removing servers in the network (horizontal scaling) or migrating to larger and faster server machines (vertical scaling).
Q10. Event Handling in JavaScript
Event Handling in JavaScript is a software routine that processes actions that happen when a user interacts with the page, such as mouse movements and keystrokes. Event handlers in javascript are when an event is received by an event handler from an event producer and the processes that follow. Events are handled similarly in a browser. When the browser notices a change, it notifies an event handler (a function) that is listening to a specific event. The actions are then carried out as defined by these functions.
Q11. Different Event Handlers in JS
- onclick: When a click action occurs on an HTML element, this event handler runs a JavaScript script.
- onload: When a window or image has fully loaded, this event handler executes some JavaScript code.
- onkeypress: When a user presses a key, this event handler executes JavaScript code.
- onmouseover: When the mouse is over a particular link or object, this event handler runs a JavaScript script.
Q12. Define DOM
The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.
Q13. What is XML?
Extensible Markup Language (XML) lets you define and store data in a shareable manner. XML supports information exchange between computer systems such as websites, databases, and third-party applications.
Q14. What are the Applications of XML?
- Data transfer: You can use XML to transfer data between two systems that store the same data in different formats.
- Web applications: XML gives structure to the data that you see on webpages. Other website technologies, like HTML, work with XML to present consistent and relevant data to website visitors.
- Documentation: You can use XML to specify the structural information of any technical document.
- Data type: Many programming languages support XML as a data type. you can easily write programs in other languages that work directly with XML files.
Q15. How is XML Different from HTML?
The purpose of HTML is to present and display data. However, XML stores and transports data. HTML has predefined tags, but users can create and define their own tags in XML. XML is case sensitive, but HTML is not. XML parsers will give errors if you write a tag as <Book> instead of <book>.
Q16. Write PHP Code to Check Whether a Number “n” is Prime or Not
<!DOCTYPE html>
<html>
<head>
<title>Prime Number Checker</title>
</head>
<body>
<h2>Prime Number Checker</h2>
<form method="post">
<label for="number">Enter a number:</label>
<input type="number" name="number" id="number" required>
<button type="submit" name="check">Check Prime</button>
</form>
<?php
function isPrime($number) {
if ($number <= 1) {
return false;
}
for ($i = 2; $i <= sqrt($number); $i++) {
if ($number % $i === 0) {
return false;
}
}
return true;
}
if (isset($_POST['check'])) {
$inputNumber = $_POST['number'];
if (is_numeric($inputNumber)) {
$result = isPrime($inputNumber) ? "Prime" : "Not Prime";
echo "<p>$inputNumber is $result.</p>";
} else {
echo "<p>Please enter a valid number.</p>";
}
}
?>
</body>
</html>
Q17. JS to Multiply
<table>
<thead>
<tr>
<th>Multiplier</th>
<th>Result</th>
</tr>
</thead>
<tbody id="multiplicationTableBody">
</tbody>
</table>
<script>
var tableBody = document.getElementById("multiplicationTableBody");
for (var i = 1; i <= 10; i++) {
var row = tableBody.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.textContent = i;
cell2.textContent = i * 3;
}
</script>
Q18. XML Features
- Excellent for handling data with a complex structure or atypical data.
- Text data description.
- Human- and computer-friendly format.
- Excellent for long-term data storage and data reusability.
Q19. PHP Loops
1. While Loop
The while loop executes a block of code as long as the specified condition is true.
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
2. Do…While Loop
The do…while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
3. For Loop
The for loop is used when you know in advance how many times the script should run.
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
4. Foreach Loop
The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.
$colors = array("red", "yellow", "blue", "green");
foreach ($colors as $value) {
echo "$value <br>";
}
Q20. PHP and JavaScript Arrays
PHP Arrays
In PHP, there are three types of arrays:
- Indexed arrays: Arrays with a numeric index
- Associative arrays: Arrays with named keys
- Multidimensional arrays: Arrays containing one or more arrays
Example: $cars = array("Volvo", "BMW", "Toyota");
JavaScript Arrays
Example:
const cars = ["Saab", "Volvo", "BMW"];
let car = cars[0];
Opening and Closing Database Connection in PHP
Opening Database Connection
<?php
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Closing Database Connection
<?php
$conn->close();
?>
