2 Iaimp
2 Iaimp
This is where you include JavaScript that is meant to be loaded before the page content. It's
typically used for code that sets up variables, functions, or event handlers that are needed as soon
as the page starts to load.
JavaScript in the <head>: Useful for functions and variables needed as soon as possible. You
might use this approach to set up global variables or functions that should be available throughout
the page load.
Example:
2) What are the different methods of window object that create dialog boxes for user interaction
in Javascripts.
JavaScript supports three important types of dialog boxes. These dialog boxes can be used to
raise and alert, or to get confirmation on any input or to have a kind of input from the users.
3) How do you create arrays in Javascript? Explain the various array methods with examples.
The most common way to create an array is using array literals. This method is straightforward and
often used in practice.
The syntax of creating array using array literal is given below:
4) Define JavaScript Array. Explain the two different ways to create arrays in JavaScript.
A JavaScript array is a special type of object used to store multiple values in a single variable.
Arrays in JavaScript are ordered collections of elements, which can be of any type, including
numbers, strings, objects, and even other arrays.
They provide a way to group related data together and access it using an index.
5) a) Explain how user defined functions will be crated in JavaScript. Give example code.
In JavaScript, user-defined functions are created to encapsulate reusable code into a single block that
can be invoked whenever needed. Functions help in organizing code, reducing redundancy, and
improving readability. Here's a detailed explanation of how to create and use user-defined functions
in JavaScript.
A user-defined function in JavaScript is created using the function keyword followed by a name, a
set of parentheses (), and a block of code enclosed in curly braces {}.
Syntax:
1. Create a function
Creating a function
function test(){
document.write(“I am Function”);
test()
b) Write a JavaScript that accepts a value ‘n’ as a input from the user and display the first ‘n’
Fibonacci numbers as output.
<!DOCTYPE html>
<html>
<head><title> LabProgram3 </title>
<script type="text/javascript">
function disp( )
{
var fib;
var n=document.getElementById('t1').value;
var a=0,b=1;
document.write("<h2>fibonacci Series<br/>");
document.write("================<br/>");
document.write(a+"<br/>"+b+"<br/></h2>");
for(var i=2;i<n;i++)
{
fib=a+b;
a=b;
b=fib;
document.write("<h2>"+fib+"<br/></h2>")
}
}
</script>
</head>
<body bgcolor="lightyellow">
<form id="f1">
<h2> Enter the limit to Generate fibonacci series:<input type="text"
id="t1"/></h2>
<center><h2><input type="button" onclick="disp()" value="Click here to
display fibonacci series"/> </h2></center>
</form>
</body>
</html>
6) What is Events & Events Handling? Explain the event handling in with an example.
In JavaScript, an event is an action that occurs on a web page, such as a mouse click, key press, or page
load. Event handling is the process of responding to these events with a specific action or set of
actions.
Event handling in JavaScript is a technique that allows you to run specific code in response to certain
actions or occurrences (events) within a web page. These events could be user interactions such as
clicks, key presses, or form submissions, or they could be system-generated events like loading the
page or resizing the window.
Event handling in JavaScript typically involves:
1. Event Listener: An event listener is a function that waits for an event to occur. It "listens" for the event
and then executes a specified action when the event happens.
2. Event Handler: An event handler is the function that is called when an event occurs. It contains the
code that will be executed in response to the event.
3. Event Object: The event object represents the event that occurred. It contains information about the
event, such as the type of event, the element that triggered the event, and any relevant data (e.g.,
mouse coordinates).
7) Demonstrate with Suitable examples onclick and onfocous events.
The onclick and onfocus events in JavaScript allow you to handle user interactions with HTML elements.
onclick: This event is triggered when an element is clicked.
onfocus: This event is triggered when an element gains focus (e.g., when a user clicks on an input
field or navigates to it using the keyboard).
Examples
Example 1: onclick Event
This example demonstrates how to use the onclick event to handle a button click. When the button is
clicked, a message is displayed.
<!DOCTYPE html>
<html>
<head>
<title>onclick Event Example</title>
<script type="text/javascript">
function showMessage() {
alert('Button was clicked!');
}
</script>
</head>
<body>
<button onclick="showMessage()">Click Me</button>
</body>
</html>
function unhighlightField(event) {
event.target.classList.remove('focused');
}
</script>
</head>
<body>
<input type="text" placeholder="Focus on me" onfocus="highlightField(event)"
onblur="unhighlightField(event)">
</body>
</html>
Regular expression are used in a text search technique called pattern matching It is a pattern of characters
following special syntax to search text for matching pattern
It can find single character, words and complex pattern of characters Pattern matching and regular
expression are used for validation, replacing text,processing user input and parsing text
Construct regular expression for the pattern and use javascript method to find matching string in text
Eg:
literal- it is any character we use in search or match expression To find windows the ind is a literal string
metacharacter- it is special character not used as literals in search expression
eg ^- ^win find “Microsoft Windows” it looks only in the beginning of target string so it will not find win
but “Mozilla Browser” it will find ^Moz
Basic Syntax of Regular Expressions
Literal Characters: Matches the exact characters. For example, /hello/ matches "hello".
Metacharacters: Special characters that control the search pattern.
o .: Matches any single character except newline.
o ^: Matches the start of a string.
o $: Matches the end of a string.
o *: Matches 0 or more occurrences of the preceding element.
9) Develop and demonstrate, a XHTML document that collects the USN(the valid format is
: A digit from 1 to 4 followed by two upper-case characters followed by two digits
followed by three uppercase characters followed by two digits; (no embedded spaces are
allowed) from the user. Use JavaScript that validate the content of the document. Suitable
messages should be display in the alert if errors are detected in the input data.
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>USN Validation</title>
<script type="text/javascript">
function validateUSN() {
if (!usnPattern.test(usn)) {
alert("Invalid USN format. Please ensure the format is: Digit (1-4) + Two uppercase letters +
Two digits +
return false;
alert("USN is valid.");
return true;
</script>
</head>
<body>
</form>
</body>
</html>
(10M)
Module – 3
10) What is Bootstrap? Explain the Bootstrap file structure with a neat diagram. And give an example
for basic HTML template by using Bootstrap.
Bootstrap includes a grid system, pre-defined styles for typography, forms, buttons, navigation,
and various UI components that help maintain consistency across web applications.
A typical Bootstrap project includes several key directories and files. Here’s a basic structure.
11) What is Bootstrap? What are the features of Bootstrap? Create a webpage using Bootstrap.
Features of Bootstrap
Bootstrap offers a wide range of features that enhance web development. Some key features include:
1. Responsive Grid System: A flexible grid layout that adjusts to various screen sizes.
2. Predefined Components: Ready-to-use components such as buttons, modals, dropdowns, and navigation
bars.
3. Customizable Themes: Options to customize Bootstrap’s appearance using Sass variables or by overriding
CSS.
4. JavaScript Plugins: Built-in plugins for interactive elements like carousels, tooltips, and popovers.
5. Utility Classes: Classes for spacing, colors, text alignment, and more, allowing for quick styling.
6. Cross-Browser Compatibility: Ensures consistent display across different web browsers.
7. Mobile-First Approach: Designed with a mobile-first philosophy, ensuring optimal viewing on smaller
devices.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body class="bg-light text-dark">
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This part is inside a .container class.</p>
</div>
</body>
</html>
13) Explain with an example, the Bootstrap elements of Button and Button Group. (10M)
14) What is the responsive web design? Develop a Bootstrap program to add zebra-stripes to a table.
(10M)
15) Discuss the various forms of accessing XHTML elements in JavaScript with an example.
16) List and explain Form & Custom form classes available in Bootstrap CSS. Explain with an example.
(10M)
17) Explain the form validations in Bootstrap. Develop a Bootstrap program to create a staked form with
2 input fields, 1 checkbox and submit button. (10M)
18) Explain the following Bootstrap elements
i) Utilities ii) Classes iii) alerts. (10M)
19) a) Explain in detail Grid System in Bootstrap. (5M)
b) Explain Bootstrap containers.