0% found this document useful (0 votes)
3 views

CSS Codes

The document contains various JavaScript programming tasks and examples, including form validation, cookie management, and event handling. It covers topics such as disabling right-click, text rollover, and evaluating checkbox selections, along with code snippets for each example. Additionally, it discusses ways to protect web pages and includes tasks related to regular expressions and user account validation.

Uploaded by

vawagav635
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CSS Codes

The document contains various JavaScript programming tasks and examples, including form validation, cookie management, and event handling. It covers topics such as disabling right-click, text rollover, and evaluating checkbox selections, along with code snippets for each example. Additionally, it discusses ways to protect web pages and includes tasks related to regular expressions and user account validation.

Uploaded by

vawagav635
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

CSS Winter 19

4. Attempt any THREE of the following : 12

(b) List ways of protecting your web page and describe any one of them.
Ans.
1)Hiding your source code
2)Disabling the right MouseButton
<!DOCTYPE html>
<html>
<head>
<title>Disable Right Click</title>
</head>
<body>
<h2>Right-Click Disabled</h2>
<p>Try right-clicking on this page.</p>
<script>
document.addEventListener("contextmenu", function(event) {
event.preventDefault();
alert("Right-click is disabled on this page.");
});
</script>
</body>
</html>

3) Hiding JavaScript
4) Concealing E-mail address.

(d) Explain text rollover with suitable example.


Ans.
<!DOCTYPE html>
<html>
<head>
<style>
.rollover-text {
color: black;
font-size: 20px;
}
</style>
</head>
<body>
<h2>Text Rollover Example</h2>
<p id="text" class="rollover-text">Hover over this text</p>

<script>
let textElement = document.getElementById("text");
textElement.addEventListener("mouseover", function() {
textElement.style.color = "blue";
textElement.style.fontSize = "24px";
});
textElement.addEventListener("mouseout", function() {
textElement.style.color = "black";
textElement.style.fontSize = "20px";
});
</script>
</body>
</html>

(e) Write a Java script to modify the status bar using on MouseOver and on
MouseOut with links. When the user moves his mouse over the link, it will
display “MSBTE” in the status bar. When the user moves his mouse away
from the link the status bar will display nothing.
Ans.
<!DOCTYPE html>
<html>
<head>
<title>Status Bar Example</title>
<style>
#statusBar {
height: 20px;
margin-top: 20px;
background-color: #f0f0f0;
border: 1px solid #ccc;
padding: 5px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h2>Simulated Status Bar Example</h2>
<p>
<a href="https://www.example.com"
onmouseover="showStatus('MSBTE')"
onmouseout="showStatus('')">Hover over this link</a>
</p>
<div id="statusBar"></div>

<script>
// Function to update the simulated status bar
function showStatus(message) {
document.getElementById("statusBar").innerText = message;
}
</script>
</body>
</html>
5. Attempt any TWO of the following : 12

(b) Describe, how to read cookie value and write a cookie value. Explain with
example.
Ans.

(c) Write a Java script that displays textboxes for accepting name & email ID & a
submit button. Write Java script code such that when the user clicks on submit
button
(1) Name Validation
(2) Email ID validation
Ans.
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
</head>
<body>
<h2>User Input Validation</h2>
<form id="userForm">
<label for="name">Name:</label>
<input type="text" id="name" placeholder="Enter your name"><br><br>
<label for="email">Email ID:</label>
<input type="text" id="email" placeholder="Enter your email"><br><br>
<button type="button" onclick="validateForm()">Submit</button>
</form>
<p id="message" style="color: red;"></p>

<script>
function validateForm() {
let name = document.getElementById("name").value;
let email = document.getElementById("email").value;
let message = "";

// Name validation: must not be empty and should contain only alphabets
if (name === "" || !/^[a-zA-Z\s]+$/.test(name)) {
message = "Please enter a valid name (letters and spaces only).";
}
// Email validation: must follow the standard email format
else if (email === "" || !/^\S+@\S+\.\S+$/.test(email)) {
message = "Please enter a valid email address.";
}
// If both validations pass
else {
message = "Form submitted successfully!";
document.getElementById("message").style.color = "green";
}

// Display the message


document.getElementById("message").innerText = message;
}
</script>
</body>
</html>

6. Attempt any TWO of the following : 12


(a) Describe how to evaluate checkbox selection. Explain with suitable example.
Ans.
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Selection Example</title>
<script>
function evaluateCheckbox() {
// Get the checkbox element
const checkbox = document.getElementById("terms");
const message = document.getElementById("message");

// Check if the checkbox is selected


if (checkbox.checked) {
message.innerText = "Checkbox is selected!";
} else {
message.innerText = "Checkbox is not selected!";
}
}
</script>
</head>
<body>
<h2>Checkbox Selection Example</h2>
<form>
<label>
<input type="checkbox" id="terms">
I agree to the terms and conditions
</label><br><br>
<button type="button" onclick="evaluateCheckbox()">Check Selection</button>
</form>
<p id="message" style="font-weight: bold;"></p>
</body>
</html>

CSS Summer 22

(e) Write a javascript program to changing the contents of a window.


Ans.
<!DOCTYPE html>
<html>
<head>
<title>Change Window Content</title>
</head>
<body>
<h2>Change Window Content Example</h2>
<p id="content">This is the original content of the window.</p>
<button onclick="changeContent()">Change Content</button>

<script>
function changeContent() {
// Change the content of the window
document.getElementById("content").innerText = "The content has been changed
dynamically!";
}
</script>
</body>
</html>

(g) Write a javascript syntax to accessing elements of another child window.


Ans.
// Open a child window
let childWindow = window.open('child.html', 'ChildWindow', 'width=600,height=400');
// Access elements of the child window (after it has loaded)
childWindow.onload = function() {
let element = childWindow.document.getElementById("childElementId");
console.log(element); // Logs the child element
};
2. Attempt any THREE of the following :

(a) Write a javascript program to validate user accounts for multiple set of user
ID and password (using swith case statement).
Ans.

(b) Differentiate between concat() and join() methods of array object.


Ans.

(c) Write a javascript program to demonstrate java intrinsic function.


Ans.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Intrinsic Functions</title>
</head>
<body>
<h2>Intrinsic Functions Demo</h2>
<p id="result"></p>
<script>
// Demonstrating intrinsic functions
function demonstrateIntrinsicFunctions() {
// 1. Math functions
let number = -42.7;
let absValue = Math.abs(number); // Absolute value
let roundedValue = Math.round(number); // Round to nearest integer
// 2. String functions
let text = "Hello, JavaScript!";
let upperText = text.toUpperCase(); // Convert to uppercase
let substring = text.substring(7, 17); // Extract substring
// 3. Date functions
let now = new Date(); // Get current date and time
let year = now.getFullYear(); // Extract year
// Displaying the results
let result = `
<strong>Math Functions:</strong><br>
Absolute value of ${number} = ${absValue}<br>
Rounded value of ${number} = ${roundedValue}<br><br>
<strong>String Functions:</strong><br>
Uppercase text: ${upperText}<br>
Substring: ${substring}<br><br>
<strong>Date Functions:</strong><br>
Current year: ${year}<br>
`;
document.getElementById("result").innerHTML = result;
}
// Call the function to display results
demonstrateIntrinsicFunctions();
</script>
</body>
</html>

(d) Design a webpage that displays a form that contains an input for user name
and password. User is prompted to enter the input user name and password
and password become value of the cookies. Write the javascript function for
storing the cookies.
Ans.
<!DOCTYPE html>
<html>
<head>
<title>Store Cookies Example</title>
</head>
<body>
<h2>Login Form</h2>
<form onsubmit="storeCookies(); return false;">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br><br>

<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br><br>

<button type="submit">Submit</button>
</form>
<script>
// Function to store username and password in cookies
function storeCookies() {
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
// Store the values in cookies
document.cookie = `username=${username}; path=/`;
document.cookie = `password=${password}; path=/`;

alert("Cookies have been set!");


}
</script>
</body>
</html>
3. Attempt any THREE of the following : 12
(a) Write a javascript program to create read, update and delete cookies.
Ans. <!DOCTYPE html>
<html>
<head>
<title>Cookie Operations Example</title>
</head>
<body>
<h2>Cookie Operations</h2>

<form id="cookieForm">
<label for="cookieName">Cookie Name:</label><br>
<input type="text" id="cookieName" required><br><br>

<label for="cookieValue">Cookie Value:</label><br>


<input type="text" id="cookieValue" required><br><br>

<button type="button" onclick="createCookie()">Create Cookie</button>


<button type="button" onclick="readCookie()">Read Cookie</button>
<button type="button" onclick="updateCookie()">Update Cookie</button>
<button type="button" onclick="deleteCookie()">Delete Cookie</button>
</form>

<p id="cookieResult"></p>

<script>
// Create a cookie
function createCookie() {
const name = document.getElementById("cookieName").value;
const value = document.getElementById("cookieValue").value;
document.cookie = `${name}=${value}; path=/`; // Setting cookie with path
document.getElementById("cookieResult").innerText = `Cookie created: ${name}=$
{value}`;
}

// Read a cookie
function readCookie() {
const name = document.getElementById("cookieName").value;
const cookies = document.cookie.split("; ");
let cookieValue = null;

for (let i = 0; i < cookies.length; i++) {


const [cookieName, cookieVal] = cookies[i].split("=");
if (cookieName === name) {
cookieValue = cookieVal;
break;
}
}

if (cookieValue) {
document.getElementById("cookieResult").innerText = `Cookie found: $
{name}=${cookieValue}`;
} else {
document.getElementById("cookieResult").innerText = `Cookie not found: $
{name}`;
}
}

// Update a cookie
function updateCookie() {
const name = document.getElementById("cookieName").value;
const value = document.getElementById("cookieValue").value;
document.cookie = `${name}=${value}; path=/`; // Update cookie
document.getElementById("cookieResult").innerText = `Cookie updated: ${name}=$
{value}`;
}

// Delete a cookie
function deleteCookie() {
const name = document.getElementById("cookieName").value;
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC`; //
Set an expired date to delete cookie
document.getElementById("cookieResult").innerText = `Cookie deleted: ${name}`;
}
</script>
</body>
</html>

(b) Write a javascript program to link banner advertisements to different URLs.


Ans.

(c) Write a javascript program to calculate add, sub, multiplication and division
of two number (input from user). Form should contain two text boxes to input
numbers of four buttons for addition, subtraction, multiplication and division.
Ans.

(d) State what is regular expression. Explain its meaning with the help of a
suitable example.
Ans.

4. Attempt any THREE of the following : 12


(a) Differentiate between For-loop and For-in loop.
Ans.

(b) Write a javascript function that accepts a string as a parameter and find the
length of the string.
Ans.

(c) Write a javascript program to validate email ID of the user using regular
expression.
Ans.

(d) Write a javascript program to design HTML page with books information in
tabular format, use rollovers to display the discount information.
Ans.

(e) List ways of protecting your webpage and describe any one of them.
Ans.

5. Attempt any TWO of the following : 12


(a) Write a javascript to checks whether a passed string is palindrome or not.
Ans.

(b) Develop javascript to convert the given character to unicode and vice-versa.
Ans.

(c) Write a javascript program to create a silde show with the group of six
images, also simulate the next and previous transition between slides in your
javascript.
Ans.

6. Attempt any TWO of the following : 12


(a) Write a javascript to open a new window and the new window is having two
frames. One frame containing buthon as “click here !”, and after clicking this
button an image should open in the second frame of that child window.
Ans.

(b) Write a javascript to create option list containing list of images and then
display images in new window as per selection.
Ans.

(c) Write a javascript function to generate Fibonacci series till user defined limit.
Ans.

CSS Summer 22

2. Attempt any THREE of the following :

(a) Write a javascript program to validate user accounts for multiple set of user
ID and password (using swith case statement).
Ans.
(c) Write a javascript program to demonstrate java intrinsic function.
Ans.

(d) Design a webpage that displays a form that contains an input for user name
and password. User is prompted to enter the input user name and password
and password become value of the cookies. Write the javascript function for
storing the cookies.
Ans.

3. Attempt any THREE of the following : 12


(a) Write a javascript program to create read, update and delete cookies.
Ans.

(b) Write a javascript program to link banner advertisements to different URLs.


Ans.

(c) Write a javascript program to calculate add, sub, multiplication and division
of two number (input from user). Form should contain two text boxes to input
numbers of four buttons for addition, subtraction, multiplication and division.
Ans.

(d) State what is regular expression. Explain its meaning with the help of a
suitable example.
Ans.

4. Attempt any THREE of the following : 12


(a) Differentiate between For-loop and For-in loop.
Ans.

(b) Write a javascript function that accepts a string as a parameter and find the
length of the string.
Ans.

(c) Write a javascript program to validate email ID of the user using regular
expression.
Ans.

(d) Write a javascript program to design HTML page with books information in
tabular format, use rollovers to display the discount information.
Ans.

(e) List ways of protecting your webpage and describe any one of them.
Ans.

5. Attempt any TWO of the following : 12


(a) Write a javascript to checks whether a passed string is palindrome or not.
Ans.
(b) Develop javascript to convert the given character to unicode and vice-versa.
Ans.

(c) Write a javascript program to create a silde show with the group of six
images, also simulate the next and previous transition between slides in your
javascript.
Ans.

6. Attempt any TWO of the following : 12


(a) Write a javascript to open a new window and the new window is having two
frames. One frame containing buthon as “click here !”, and after clicking this
button an image should open in the second frame of that child window.
Ans.

(b) Write a javascript to create option list containing list of images and then
display images in new window as per selection.
Ans.

(c) Write a javascript function to generate Fibonacci series till user defined limit.
Ans.

CSS Winter 22

2. Attempt any THREE of the following :


(a) Write a JavaScript program that will display current date in DD/MM/YYYY
format.
Ans.

(b) Write a JavaScript program that will remove the duplicate element from an
array
Ans.

(c) Write a JavaScript program that will display list of student in ascending order
according to the marks & calculate the average performance of the class.
Ans.

(d) Write and explain a string functions for converting string to number and
number to string.
Ans.

3. Attempt any THREE of the following :


(b) Write a JavaScript function to check the first character of a string is uppercase
or not.
Ans.

(c) Write a JavaScript function to merge two array & removes all duplicate
values.
Ans.
(d) Write a JavaScript function that will open new window when the user will
clicks on the button.
Ans.

4. Attempt any THREE of the following :


(a) Describe text Rollover with the help of example.
Ans.

(b) Write a JavaScript program that will create pull-down menu with three
options. Once the user will select the one of the options then user will
redirected to that website.
Ans.

(c) Describe Quantifiers with the help of example.


Ans.

(d) Describe frameworks of JavaScript & its application.


Ans.

(e) Describe how to link banner advertisement to URL with example.


Ans.

5. Attempt any TWO of the following :


(a) Write HTML script that will display following structure
Write the JavaScript code for below operations :
(1) Name, Email & Pin Code should not be blank.
(2) Pin Code must contain 6 digits & it should not be accept any characters
Ans.

(b) Write a webpage that displays a form that contains an input for username &
password. User is prompted to entre the input & password & password
becomes the value of the cookie. Write a JavaScript function for storing the
cookie. It gets executed when the password changes
Ans.

(c) Write a JavaScript for creating following frame structure :


Ans.

Chapter 1 & Chapter 2 are linked to the webpage Ch1 HTML & Ch2.html
respectively. When user click on these links corresponding data appears in
FRAME3.

6. Attempt any TWO of the following :


(a) Write HTML script that will display dropdown list containing options such as
Red, Green, Blue & Yellow. Write a JavaScript program such that when the
user selects any options. It will change the background colour of webpage.
Ans.

(b) Develop a JavaScript program to create Rotating Banner Ads.


Ans.
(c) Write a JavaScript for the folding tree menu.
Ans.

CSS Winter 23

2. Attempt any THREE :


(a) Write a JavaScript that accepts a number and displays addition of digits of that
number in a message box.
Ans.

(b) Describe the “navigator” object of JavaScript. Describe the methods of


navigator object which is used to display browser name and version.
(c) Give syntax of and explain for-in loop in JavaScript with the help of suitable
example.
(d) Write an HTML script that accepts Amount, Rate of Interest and Period from
user. When user submits the information a JavaScript function must calculate
and display simple interest in a message box. (Use formula S.I. = PNR/100)
3. Attempt any THREE :
(a) Write an HTML Script that displays the following webpage output
The user enters two numbers in respective text boxes. Write a JavaScript such
that when user clicks “add”, a message box displays sum of two entered
numbers, if the user clicks on “sub”, message box displays subtraction of two
numbers and on clicking “mul” the message box displays multiplication of
two numbers.
Ans.

(b) Write a JavaScript that accepts user’s first name and domain name of
organization from user. The JavaScript then forms email address as
<firstname@domain name> and displays the results in the browser window.
Ans.

(c) Differentiate between substring() and substr() method of a string class. Give
suitable example of each.
Ans.

(d) State what is a cookie ? Explain its need. State characteristics of persistent
cookies
Ans.

4. Attempt any THREE :


(a) Write a JavaScript that accepts a string and searches for the pattern “MSBTE”
in the given string using regular expressions. If the pattern is found,
JavaScript will display that “Pattern is found” else display “Pattern is not
found”.
Ans.

(b) List and state various properties of a window object. Write a JavaScript that
opens a new popup window with message “WELCOME To SCRIPTING”
when the page loads and a new popup window displaying message “FUN
WITH SCRIPTING” when the page unloads.
Ans.

(c) Write an HTML script that displays names of different brands of Laptop and
an image by default as :
When the mouse moves over the specific brand name the script must display
the image of respective Laptop in the adjacent box.
Ans.

(d) Give syntax of and explain the use of SetTime Out( ) function with the help of
suitable example.
Ans.

(e) State the use of hiding the JavaScript. Explain the steps needed to accomplish
it and describe the process.
5. Attempt any TWO :
(a) Write a JavaScript that demonstrates use of floating menu alongwith
respective HTML script.
Ans.

(b) Form regular expressions for following :


(i) Validation of email address.
(ii) Validation of adhaar card. Format is
dddd – dddd – dddd
(iii) Validation of phone number. Format is
(ddd) – (dddddddd)
Ans.

(c) Write HTML and respective JavaScript such that


(i) Webpage displays three checkboxes as
(ii) When a beverage is selected a dropdown list with options as below
appears on page :
(a) If “TEA” option is checked dropdown list contains
Green tea
Milk tea
Black tea
(b)
If “COFFEE” option is selected dropdown list contains.
Capaccino
Latte
Expression
(c)
If “SOFT DRINK” option is selected dropdown list contains
MAAZA
SPRITE
COCA-COLA
Ans.

6. Attempt any TWO :


(a) List and explain any six form events.
Ans.

(b) Write a JavaScript that sets a crawling status bar message to the webpage.
Message is “Welcome to the Mystic World of JavaScript”.
The message must start crawling when the webpage gets loaded.
Ans.

(c)
(i) Design frameset tag for representing following layout :
(ii) List any three properties of regular expression objects and state their
use
Ans.

CSS Summer 24

2. Attempt any THREE of the following:12

a) State the use of Object, Method and Property in JavaScript.


Ans.

b) Explain setter and getter properties in JavaScript with the help of suitable example.
Ans.

c) Write a JavaScript program to check whether a number is positive, negative or zero


using switch case.
Ans.
d) State the use of following methods:
i) charCodeAt()
ii) fromCharCode ()
Ans.

3. Attempt any THREE of the following:12

a) Explain Associative arrays in detail.


Ans.
b) Write a JavaScript function that checks whether a passed string is palindrome or
not.
Ans.
c) Explain how to add and sort elements in array with suitable example.
Ans.
d) Explain the term browser location and history in details.
Ans.

4. Attempt any THREE of the following:12

a) State what is frame? Explain how it can be created with suitable example.
Ans.

b) Explain the steps to create floating menu and chain select menu
Ans.

c) Explain how to use banners for displaying advertisement.


Ans.
d) Write a JavaScript function to check whether a given address is a valid IP address or
not.
Ans.
e) Explain process to create status bar in JavaScript.
Ans.
5. Attempt any TWO of the following:12

a) Write HTML script that displays textboxes for accepting username and password.
Write proper JavaScript such that when the user clicks on submit button
i) All textboxes must get disabled and change the color to 'RED' and with respective
labels.
ii) Prompt the error message if the password is less than six characters.
Ans.
b) Write a webpage that displays a form that contains an input for students rollno and
names user is prompted to enter the input student rollno and name and rollno becomes
value of the cookie.
Ans.
c) Write a JavaScript to create rollover effect that involves text and images. When the
user places his or her mouse pointer over a book title, the corresponding book image
appears.
Ans.
6. Attempt any TWO of the following:12

a) Explain following form control/elements with example Button, Text, TextArea, Select
Checkbox, Form.
Ans.

b) Write a JavaScript for protecting web page by implementing the following steps:
i) Hiding your source code
ii) Disabling the right MouseButton
iii) Hiding JavaScript
Ans.
c) Develop a JavaScript to create rotating Banner Ads with URL links.
Ans.

You might also like