Web Tech Guide for Students
Web Tech Guide for Students
4. Describe the steps involved for web browser requests & responses of web pages from a web server.
Ans: The process of a web browser making a request to a web server and receiving a response to display a web
page involves several steps. Here's an overview:
1. URL Entry: The user enters a URL (Uniform Resource Locator) into the web browser's address bar. The
URL specifies the location of the desired web page on the internet.
2. DNS Lookup: The browser checks its cache to see if it already knows the IP address associated with the
domain name in the URL. If not, it sends a DNS (Domain Name System) request to a DNS server to resolve the
domain name into an IP address.
3. TCP Connection: Once the browser has the IP address of the web server, it initiates a TCP (Transmission
Control Protocol) connection to that server. This involves a three-way handshake to establish the connection.
4. HTTP Request: After the TCP connection is established, the browser sends an HTTP (Hypertext Transfer
Protocol) request to the web server. This request includes information such as the requested resource (specified
in the URL), any additional headers (such as cookies or user-agent information), and the HTTP method (usually
GET for requesting a web page).
5. Server Processing: The web server receives the HTTP request and processes it. This may involve accessing
databases, executing scripts, or retrieving files from storage to generate the content of the requested web page.
6. HTTP Response: Once the server has processed the request, it sends an HTTP response back to the browser.
This response includes a status code (indicating the success or failure of the request), response headers
(providing metadata about the response), and the actual content of the web page (typically HTML, along with
any associated CSS, JavaScript, images, etc.).
7. Data Transfer: The browser receives the HTTP response and begins downloading the content of the web
page. This may involve multiple TCP packets being sent from the server to the browser.
8. Rendering: As the browser receives the content, it begins to render the web page, parsing the HTML,
applying styles from CSS, executing JavaScript, and loading any additional resources (such as images or fonts)
referenced in the HTML.
9. Display: Finally, once the browser has finished rendering the web page, it displays the content to the user in
the browser window.
Throughout this process, there may be additional steps involved depending on factors such as caching, HTTPS
encryption, and content compression. However, these are the fundamental steps involved in a typical web
browser request and response cycle.
5.List various tags in HTML with simple example for a web page.
Ans: HTML (Hypertext Markup Language) uses tags to define the structure and content of a web page. Here
are some common HTML tags along with simple examples:
1. <!DOCTYPE>: Defines the document type and version of HTML being used.
Example:
```html
<!DOCTYPE html>```
2. <html>: Defines the root element of an HTML document.
Example:
```html
<html>
<!-- HTML content goes here -->
</html>```
3. <head>: Contains metadata about the document, such as title, links to stylesheets, and scripts.
Example:
```html
<head>
<title>My Web Page</title>
</head>```
4. <title>: Sets the title of the document (usually displayed in the browser's title bar).
Example:
```html
<title>My Web Page</title>```
5. <body>: Contains the main content of the HTML document.
Example:
```html
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph of text.</p>
</body>```
6. <h1>, <h2>, ..., <h6>: Defines headings of different levels.
Example:
```html
<h1>Main Heading</h1>
<h2>Subheading</h2>```
7. <p>: Defines a paragraph of text.
Example:
```html
<p>This is a paragraph of text.</p>```
8. <a>: Defines a hyperlink.
Example:
```html
<a href="https://www.example.com">Visit Example</a>```
9. <img>: Insert an image into the document.
Example:
```html
<img src="image.jpg" alt="Description of the image">```
10. <ul>, <ol>: Defines an unordered or ordered list, respectively.
Example:
```html
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>```
11. <li>: Defines a list item within a <ul> or <ol> element.
Example:
```html
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>```
12. <div>: Defines a division or section of the document.
Example:
```html
<div>
<p>This is a paragraph inside a division.</p>
</div>```
13. <span>: Defines a span of text within a document.
Example:
```html
<p>This is <span>highlighted</span> text.</p>```
14. <form>: Defines an HTML form for user input.
Example:
```html
<form action="/submit" method="post">
<input type="text" name="username" placeholder="Enter your username">
<input type="submit" value="Submit">
</form>```
These are just a few examples of HTML tags. There are many more tags available for various purposes in
HTML documents.
6. How will you create a password field in HTML Form?
Ans: To create a password field in an HTML form, you can use the <input> tag with the type attribute set
to "password". This will create an input field where the characters are masked (usually displayed as asterisks or
dots) to hide the password from prying eyes. Here’s an example of how to create a password field in an HTML
form:
<form>
<label for="user-password">Password:</label>
<input type="password" id="user-password" name="user-password">
</form>
In the above code:
The <label> element provides a clear label for the password input field.
The <input> element with type="password" creates the password field.
7. What are the hyperlinks and Anchor in the HTML? Explain with a suitable example.
Ans:
There is a common practice to specify the web link on the web page. The link acts as
a pointer to some web page or some resource.
The use of hyperlinks in the web page allows that page to link logically with other pages.
We can use hyperlinks by using a tag <a> and by specifying the URL for href.
The value assigned to the href specifies the target of the link.
The <a> means the beginning of the web link and </a> means the end of the web link.
The most important attribute of the <a> element is the href attribute, which indicates
the link's destination.
By default, links will appear as follows in all browsers:
1) An unvisited link is underlined and blue.
2) A visited link is underlined and purple.
3) An active link is underlined and red.
Following are the steps to be followed to specify the web link on the web page.
Step 1: The beginning of the web link can be specified by the tag <a href = “ “.
Inside the double quotes mention the URL of the desired link.
Step 2: Write some text that should act as a hyperlink.
Step 3: End the web link </a>
Here is a sample program that implements the above-given idea –
HTML Document [HyperlnkDemo.html]
<!DOCTYPE html>
<html>
<head>
<title> Use of Hyperlink on the Web Page </title>
</head>
<body>
click here to get a
<a href="http://www.vtubooks.com">book</a> on engineering
</body>
</html>
8. Explain how frames are constructed in an HTML document. Explain with program.
Ans: HTML frames allow us to present documents in multiple views.
Using multiple views we can keep certain information visible and at the same time other views are scrolled
or replaced.
For example, within the same window, one frame can display company information, a second frame can be a
navigation menu and a third frame may display a selected document that can be scrolled through or replaced by
navigating in the second frame.
Various frames can be set in one browser window.
To set the frames in the browser window we use frame set.
For example -
<frameset cols="150,*">
will allow us to divide the window into two columns (i.e. in two vertical frames). One frame occupies the size
of 150 pixels and the other occupies the remaining portion of the window. Here * means any number of pixels.
Similarly
<frameset rows="*,120">
will divide the window into two rows (i.e. in two horizontal frames). The second part of the horizontal frame
will be 120 pixels and the upper horizontal frame will occupy the remaining portion of the window.
Similarly, we can also specify the frameset in percentage form. For example,
<frameset rows="30%,70%">
Using frameset we can divide the rows and columns in any number of frames. For
example
<frameset rows = “20%,30%,50%” cols = “30%,*”>
This will create frames in the browser’s window as follows –
9. Describe HTML form tags with simple examples.
Ans: Certainly! Let’s delve into the world of HTML form tags. These tags play a crucial role in creating
interactive web forms that allow users to input data and submit it to a server. Here are the key points about
HTML form tags:
1. <form> Tag:
o The <form> tag is the foundation for creating forms in HTML.
o It encompasses various form elements and defines how data should be sent to the server when
the user submits the form.
o Common attributes:
action: Specifies the URL where the form data should be sent.
method: Determines the HTTP method used for form submission (usually GET or
POST).
name: Assign a name to the form.
enctype: Specifies how form data should be encoded (e.g., application/x-www-form-
urlencoded or multipart/form-data).
Example:
<form action="/submit-form" method="post">
<!-- Form elements go here -->
</form>
2. Form Elements:
o Inside the <form> tag, you can include various form elements. Some common ones include:
<input>: For text input, checkboxes, radio buttons, etc.
<textarea>: For multiline text input.
<button>: For buttons (e.g., submit or reset).
<select>: Creates a dropdown menu.
<option>: Represents an option within a <select> dropdown.
<optgroup>: Groups related options within a <select>.
<fieldset>: Groups related form elements together.
<label>: Provides a label for form controls.
<output>: Displays the result of a calculation or script.
o Example with input fields and a submit button:
o <form action="/action_page.php" method="get">
o <label for="fname">First name:</label>
o <input type="text" id="fname" name="fname"><br><br>
o <label for="lname">Last name:</label>
o <input type="text" id="lname" name="lname"><br><br>
o <input type="submit" value="Submit">
o </form>
3. Other Attributes:
o accept-charset: Specifies character encodings for form submission.
o autocomplete: Controls autocomplete behavior (e.g., on or off).
o novalidate: Prevents form validation on submission.
o target: Determines where the response will be displayed (e.g., _blank for a new tab).
Remember, HTML forms are essential for user interaction on the web. They allow users to input data, make
selections, and interact with websites effectively. Feel free to explore more examples and create your own
forms.
10. Differentiate HTML & HTML5.
Ans:
11. Explain i) Inline CSS ii) Internal CSS iii) External CSS with examples. Which one is suitable for a
Web application having more than one page?
Ans:
1. Inline CSS:
o Definition: Inline CSS involves defining styles directly within an HTML element using the style
attribute.
o Example:
<p style="color: blue; font-size: 16px;">This is some text with inline CSS.</p>
o Explanation: In the example above, the color and font size are applied directly to the <p>
element. Inline CSS is useful for quick styling changes to specific elements within a single page.
o Pros:
Quick and easy to implement.
Specific to individual elements.
o Cons:
Not reusable across multiple pages.
2. Internal CSS (Embedded CSS):
o Definition: Internal CSS is placed within the <style> element in the <head> section of an
HTML document.
o Explanation: The CSS rules target specific elements (e.g., <h1> and <p>) within the same
HTML file. It’s effective for styling a single page.
o Pros:
Applies to the entire HTML document.
Better organization than inline CSS.
o Cons:
Still not reusable across multiple pages.
o Example:
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS Example</title>
<style>
h1 {
color: blue;
font-size: 24px;
font-weight: bold;
}
p{
color: green;
font-size: 16px;
}
</style>
</head>
<body>
<h1>My Web Page</h1>
<p>Styling using internal CSS.</p>
</body>
</html>
3. External CSS:
o Definition: External CSS resides in a separate .css file linked to the HTML document using the
<link> tag.
o Syntax (in the <head> section):
o <link rel="stylesheet" type="text/css" href="styles.css">
o Explanation: The CSS rules are stored externally, making them reusable across multiple pages.
Ideal for web applications with more than one page.
o Pros:
Separation of concerns (HTML and CSS).
Reusable across multiple pages.
o Cons:
Requires an additional file.
o Example:
Create a styles.css file with the following content:
h1 {
color: blue;
font-size: 24px;
font-weight: bold;
}
p{
color: green;
font-size: 16px;
}
Link it in your HTML:
<!DOCTYPE html>
<html>
<head>
<title>External CSS Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>My Web App</h1>
<p>Styling using external CSS</p>
</body>
</html>
In summary, external CSS is the most suitable choice for a web application with multiple pages, as it promotes
reusability and maintains a clear separation between content and styling.
12. Describe what is a style sheet. How to create a multi-color text on a web page using CSS. Explain with
an example.
Ans: Style Sheet:
The CSS stands for Cascading Style Sheet.
The Cascading Style Sheet is a markup language used in the web document for presentation purposes.
The primary intention of CSS was to separate the web content from the web presentation.
Various elements such as text, font and color are used in CSS for presentation purpose. Thus CSS
specification can be applied to bring the styles in the web document.
Now, let's create a multi-color text effect on a web page using CSS:
<!DOCTYPE html>
<html>
<head>
<style>
.multicolor {
background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
-webkit-background-clip: text;
color: transparent;
font-size: 36px;
font-weight: bold;
text-align: center;
margin-top: 50px;
}
</style>
</head>
<body>
<h1 class="multicolor">Multi-color Text Example</h1>
</body>
</html>
In this example, we use the CSS “linear-gradient ()” function to create a gradient background for the text. The
“-WebKit-background-clip: text;” property allows the gradient to be clipped to the text, making it appear
multi-colored. The “color: transparent;” property ensures that the original text color is transparent, allowing
the gradient to show through. Finally, we adjust the font size, weight, and alignment to achieve the desired
effect.
13. Write a short note on Bootstrap.
Ans:
Bootstrap:
Bootstrap is an open-source, front-end web framework. It is used for designing websites and web
applications.
Bootstrap helps the developer to create responsive designs. Responsive web design means creating a
website that automatically adjusts itself to look good on all devices. These devices range from small
phones to large desktop screens.
Bootstrap includes HTML, CSS, and JavaScript-based design templates which include forms,
buttons, tables, navigation, modals, and so on.
Unit 2
1. What is JavaScript? Explain the characteristics of JavaScript.
Ans: JavaScript:
JavaScript was developed by Netscape in 1995. At that time its name was LiveScript. Later on, Sun
Microsystems joined Netscape and then they developed LiveScript. And later on, its name is changed to
JavaScript.
Characteristics of JavaScript:
1. Browser Support: For running the JavaScript in the browser there is no need to use some plug-in. Almost
all the popular browsers support JavaScripting.
2. Structure Programming Syntax: JavaScript supports much more commonly the structured language type
syntax. Similar to C-style the programming blocks can be written.
3. It automatically inserts the semicolon at the end of the statement, hence there is no need to write a semicolon
at the end of the statement in JavaScript.
4. Dynamic Typing: It supports dynamic typing, which means the data type is bound to the value and not to the
variable. For example one can assign an integer value to a variable say ‘a’ and later on can assign some strg the
ing value to the same variable in JavaScript.
5. Run Time Evaluation: Using the eval function the expression can be evaluated at run time.
6. Support for Object: JavaScript is object oriented scripting language. However, the handling of objects in
JavaScript is somewhat different from the conventional object-oriented programming languages. JavaScript has
a small number of inbuilt objects.
7. Regular Expression: JavaScript supports the use of regular expressions using which text-pattern matching
can be done. This feature can be used to validate the data on the web page before submitting it to the server.
8. Function Programming: In JavaScript, functions are used. One function can accept another function as a
parameter. Even, one function can be assigned to a variable just like some data type. The function can be run
without giving the name.
2. Write a difference between JavaScript and JQuery.
Ans:
3. How to create an array in JavaScript. Explain in the brief reading of array elements in JavaScript
with examples.
Ans: Arrays: May-18,19, Marks 5
Definition of Arrays: Arrays are a collection of similar types of elements that can be referred to by a
common name.
Any element in an array is referred to by an array name followed by “[“followed by the position of the
element followed by].
The particular position of an element in an array is called an array index or subscript.
Declaring an Array
In JavaScript, the array can be created using an Array object.
Suppose, we want to create an array of 10 elements then we can write,
var ar = new Array(10);
Using a new operator we can allocate the memory dynamically for the arrays.
In the brackets, the size of an array is mentioned and the var ar denotes the name of the array. Thus by the
above sentence, an array ar will be created in which we can store 10 elements at the most. Sometimes the above
statement can be written like this
var ar;
ar=new Array(10);
Initializing an Array
Initialization is the process of assigning a value when either a variable or array is declared. For example
int count=10//variable initialization
While initializing an array -
1) Declare the name of the array
2) Make use of the keyword new
3) Each value within an array as an ‘array element’ must be separated by a comma.
For example –
Following is a simple JavaScript that illustrates the initialization of the array by defining the array elements.
Accessing Array Elements:
To access an element in an array, use the array name followed by square brackets containing the index
number.
Array indices start at 0 for the first element, 1 for the second element, and so on
let myArray = [29, "Nathan", true];
console.log(myArray[0]); // Output: 29
console.log(myArray[1]); // Output: Nathan
4. Explain how to call the javascript function from the HTML page.
Ans: Calling a Function from with Argument
In JavaScript, we can pass an argument to the function. The following JavaScript shows how to pass an
argument to the function. In the following program, I have written a simple function for the addition of two
numbers. The values of the two numbers are 10 and 20 respectively. Inside this function, the addition of these
two arguments is carried out and the result is displayed on the Browser page.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function add(a,b)//function to which arguments a and b are passed
{
c=a+b
document.write("Addition = "+c)
}
</script>
</head>
<body>
<h4> Passing Arguments to the function </h4>
<script type="text/javascript">
var x=10;
var y=20
add(x,y)
</script>
</body>
</html>
Calling a Function without an Argument
A function can also be called without passing any argument. In this case, all the required variables are declared
and used within that function. The following program shows how to call a function without passing an
argument.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function add()
{
var a=10
var b=20
c=a+b
document.write("Addition = "+c)
}
</script>
</head>
<body>
<h4> Function without passing argument</h4>
<script type="text/javascript">
add()
</script>
</body>
</html>
5. What is the purpose of the DOM node tree? Draw a node tree for a simple HTML Page.
Ans: Purpose of the DOM node tree:
Structured Representation: It organizes the document's elements, attributes, and text content in a tree-like
structure, where each node represents an element, attribute, or piece of text.
Programmatic Access: It provides a standardized interface (API) for programs (such as JavaScript) to access
and manipulate elements and their attributes within the document. This allows dynamic modification of the
document's content and structure.
Event Handling: It facilitates event handling by allowing scripts to register event listeners on specific DOM
nodes. This enables interactivity such as responding to user actions like clicks, keyboard input, etc.
Dynamic Content Modification: This enables the dynamic modification of a web page's content and structure
in response to user interactions, AJAX requests, or other events without needing to reload the entire page.
Rendering and Styling: It serves as a foundation for rendering and applying styles to elements on the web
page, enabling dynamic changes to the visual presentation through CSS manipulation.
For example: Consider following XHTML document.
<html>
<head>
<title>This is My Web Page </title>
</head>
<body>
<h1>Hello Friends </h1>
<h2>How are you?</h2>
</h3>See you</h3>
</body>
</html>
The DOM tree will be
6. What are the different Data types available in JavaScript? Explain with correct syntax of declaration
of it.
Ans: JavaScript supports several data types, which can be broadly categorized into two groups: primitive data
types and non-primitive data types (also known as reference types).
1. Primitive Data Types:
Number: A number is a numeric value that can be an integer or float. It can be used
in calculation.
```javascript
let num = 10; // Integer
let floatNum = 3.14; // Floating-point number```
String: String is a collection of characters. It is enclosed within a single quote or double quote. A string
may contain numbers but these numbers can not be used for calculations.
```javascript
let str = 'Hello, world!'; // Single quotes
let anotherStr = "JavaScript"; // Double quotes```
Boolean: The Boolean values are true and false. These values can be compared with the variables or
can be used in assignment statements.
```javascript
let isTrue = true;
let isFalse = false;```
Null: The null value can be assigned by using the reserved word null. The null means no value. If we
try to access the null value then a runtime error will occur.
```javascript
let nullValue = null;```
Undefined: Represents a variable that has been declared but has not been assigned a value.
```javascript
let undefinedValue;```
Symbol: Represents a unique and immutable value that may be used as an identifier for object
properties.
```javascript
const sym = Symbol('description');```
2. Non-primitive Data Types (Reference Types):
Object: An object is for an entity that represents some value. For example - a window object is a value
using which the window is created. A form is an object upon which some components such as buttons,
checkboxes, and radio buttons can be placed and used.
```javascript
let person = {
name: 'John',
age: 30,
isStudent: false
};```
Array: Represents an ordered collection of elements, which can be of any data type.
```javascript
let numbers = [1, 2, 3, 4, 5];
let fruits = ['apple', 'banana', 'orange'];```
Function: Represents a reusable block of code that can be invoked with specified parameters.
```javascript
function greet(name) {
console.log('Hello, ' + name + '!');
}```
Date: Represents a date and time value.
```javascript
let currentDate = new Date();```
RegExp: Represents a regular expression object, which can be used for pattern matching within strings.
```javascript
let regex = /hello/;```
These are the basic data types available in JavaScript, each serving different purposes and used for various
programming tasks.
8. List and brief any five functions in JavaScript.
Ans:
1. console.log():
- This function is fundamental for debugging JavaScript code. It allows developers to log messages,
variables, objects, or any kind of data to the browser's console.
- It takes one or more parameters, which can be strings, variables, or objects, and outputs them to the
console.
Example:
```javascript
console.log('Hello, world!');
```
2. alert():
- The `alert()` function displays a modal dialog box with a specified message and an OK button. It's often
used for displaying alerts, notifications, or prompting users for simple interactions.
- It takes a single parameter, which is the message to be displayed in the alert dialog.
Example:
```javascript
alert('This is an alert message!');
```
3. setTimeout():
- This function is used to execute a specified function or a block of code after a specified delay (in
milliseconds). It's commonly used for scheduling tasks to be performed after a certain period.
- It takes two parameters: a function or code block to execute and the delay time in milliseconds.
Example:
```javascript
setTimeout(function() {
console.log('Delayed message after 2 seconds.');
}, 2000);
```
4. setInterval():
- Similar to `setTimeout()`, `setInterval()` is used to execute a specified function or a block of code
repeatedly at a specified interval (in milliseconds). It's often used for creating animations, periodic
updates, or timed events.
- It takes two parameters: a function or code block to execute and the interval time in milliseconds.
Example:
```javascript
let intervalId = setInterval(function() {
console.log('Repeated message every 3 seconds.');
}, 3000);
```
5. parseInt():
- The `parseInt()` function parses a string argument and returns an integer of the specified radix (the base
in mathematical numeral systems). It's commonly used for converting strings to integers.
- It takes two parameters: the string to be parsed and an optional radix (base) for numerical conversion.
Example:
```javascript
// Name validation
const name = document.getElementById('name').value.trim();
if (name === '')
{
document.getElementById('nameError').textContent = 'Name is required';
valid = false;
}
// Age validation
const age = document.getElementById('age').value.trim();
if (age === '')
{
document.getElementById('ageError').textContent = 'Age is required';
valid = false;
} else if (isNaN(age) || age < 1)
{
document.getElementById('ageError').textContent = 'Invalid age';
valid = false;
}
// Address validation
const address = document.getElementById('address').value.trim();
if (address === '')
{
document.getElementById('addressError').textContent = 'Address is required';
valid = false;
}
// Email validation
const email = document.getElementById('email').value.trim();
if (email === '')
{
document.getElementById('emailError').textContent = 'Email is required';
valid = false;
} else if (!/^\S+@\S+\.\S+$/.test(email))
{
document.getElementById('emailError').textContent = 'Invalid email';
valid = false;
}
// Country validation
const country = document.getElementById('country').value.trim();
if (country === '')
{
document.getElementById('countryError').textContent = 'Country is required';
valid = false;
}
return valid;
}
</script>
</body>
</html>
13. Explain how the object is created and modified in JavaScript.
Ans:
The web designer can create an object and can set its properties as per his
requirements.
The object can be created using new expression.
Initially the object with no properties can be set using the following statements.
Myobj=new Object();
Then using the dot operator we can set the properties for that object.
The object can then be modified by assigning the values to this object.
<!DOCTYPE html>
<html>
<head>
<title>Object Creation Demo</title>
</head>
<body>
<strong>
<script type="text/javascript">
var Myobj;
var n,i;
//creating an object
Myobj=new Object();
//setting the propertis for newly created object
Myobj.id=10;
Myobj.name="Anuradha";
document.write("The ID is "+Myobj.id+"<br/>");
document.write("The Name is "+Myobj.name);
</script>
</strong>
</body>
</html>
14. Write a program of your choice that demonstrate use of properties of DOM.
Ans:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Properties Example</title>
</head>
<body>
<h1 id="myHeading">Hello, DOM!</h1>
<p>This is a simple example to demonstrate DOM properties.</p>
<script>
// Accessing the DOM element with ID "myHeading"
const heading = document.getElementById("myHeading");