Revised CSS Kit
Revised CSS Kit
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
WINTER – 19 EXAMINATIONS
Subject Name: Client Side Scripting Model Answer Subject Code: 22519
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in
the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner
may try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components
indicated in the figure. The figures drawn by candidate and model answer may vary.
The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed
constant values may vary and there may be some difference in the candidate’s
answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of
relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based
on equivalent concept.
Page 1 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
var person = {
firstname:"John",
lastname:"Doe",
age:50,
eyecolor:"blue"
}; Delete and
display
delete person.eyecolor; //delete person eyecolor
properties :
document.write("After delete "+ person.firstname +" "+ person.lastname +" " 1M
+person.age +" "+ person.eyecolor);
</script>
</body>
</html>
d Write a Java script that initializes an array called flowers with the names of 2M
3 flowers. The script then displays array elements.
Ans <html> Initialization
of array :
<head> 1M,
Page 2 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
flowers[1] = 'Mogra';
flowers[2] = 'Hibiscus';
for (var i = 0; i < flowers.length; i++)
{
document.write(flowers[i] + '<br>');
}
</script>
</body>
</html>
e Write Javascript to call function from HTML. 2M
Ans <html> Function
declaration :
<head> 1M,
<title>Calling function from HTML</title>
<script> Function
call from
function welcome()
HTML: 1M
{
alert("Welcome students");
(Any other
} example
allowed)
function goodbye()
{
alert("Bye");
Page 3 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
}
</script>
</head>
<body onload="welcome()" onunload="goodbye()">
</body>
</html>
f Write a Javascript to design a form to accept values for user ID & password. 2M
Ans <html> Correct
syntax: 1M,
<body>
<form name="login">
Correct
Enter Username<input type="text" name="userid"><br> logic: 1M
Enter Password<input type="password" name="pswrd">
<input type="button" onclick="display()" value="Display">
</form>
<script language="javascript">
function display()
{
document.write("User ID "+ login.userid.value + "Password :
"+login.pswrd.value);
}
</script>
</body>
</html>
g State any two properties and methods of location object. 2M
Ans Properties of location object: Any 2
properties :
1. hash ½ M each
2. host
3. hostname
4. href
5. origin
Page 4 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
6. pathname
7. port
8. protocol
9. search
Any 2
Methods of location object: methods : ½
M each
1. assign( )
2. reload( )
3. replace( )
set propName(value) {
// setter, the code executed on setting obj.propName = value
}
};
Example:
<html>
Page 5 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
<head>
<title>Functions</title>
<body> Example :
<script language="Javascript"> 2M
var myCar = {
/* Data properties */
defColor: "blue",
defMake: "Toyota",
(Any other
/* Accessor properties (getters) */ example can
get color() { be
return this.defColor; considered)
},
get make() {
return this.defMake;
},
Page 6 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
else{
alert("cancel");
}
}
</script>
<input type="button" value="delete record" onclick="msg()"/>
</html>
Page 7 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
c Write a Java script program which computes, the average marks of the 4M
following students then, this average is used to determine the corresponding
grade.
Student Name Marks
Sumit 80
Kalpesh 77
Amit 88
Tejas 93
Abhishek 65
Page 8 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
document.write("Grade : E");
}
else if (avg < 70) {
document.write("Grade : D");
}
else if (avg < 80) {
document.write("Grade : C");
} else if (avg < 90) {
document.write("Grade : B");
} else if (avg < 100) {
document.write("Grade : A");
}
</script>
</body>
</html>
Output (Optional)
Average grade: 80.6
Grade : B
d Write the use of chatAt() and indexof() with syntax and example. 4M
Ans charAt() Each syntax
: 1M,
The charAt() method requires one argument i.e is the index of the character that
you want to copy.
Syntax: Example :
1M
var SingleCharacter = NameOfStringObject.charAt(index);
Example:
Page 9 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
indexOf()
The indexOf() method returns the index of the character passed to it as an
argument.
If the character is not in the string, this method returns –1.
Syntax:
var indexValue = string.indexOf('character');
Example:
var FirstName = 'Bob';
The concat() method separates each The join() method also uses a comma
value with a comma. to separate values, but you can
specify a character other than a
comma to separate values.
Eg: Eg:
var str = cars.concat() var str = cars.join(' ')
The value of str in this case is
The value of str is 'BMW Audi Maruti'
'BMW, Audi, Maruti'
b Write a JavaScript that will replace following specified value with another 4M
value in string.
Page 10 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
</body>
</head>
</html>
<script>
var arr1 = [ “Red”, “red”, “Blue”, “Green”]
document.write(“Before sorting arra1=” + arr1);
document.write(“<br>After sorting arra1=” + arr1.sort());
</script>
</body>
</html>
Page 11 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Ans The open() method of window object is used to open a new window and loads the Explanation:
document specified by a given URL. 1M
MyWindow = window.open() syntax: 1 M
The open() method returns a reference to the new window, which is assigned to
Example: 2
the MyWindow variable. You then use this reference any time that you want to
do something with the window while your JavaScript runs. M
A window has many properties, such as its width, height, content, and name—to
mention a few. You set these attributes when you create the window by passing
(Any other
them as parameters to the open() method:
example can
be
• The first parameter is the full or relative URL of the web page that will appear
considered)
in the new window.
• The second parameter is the name that you assign to the window.
• The third parameter is a string that contains the style of the window.
We want to open a new window that has a height and a width of 250 pixels and
displays an advertisement that is an image. All other styles are turned off.
Syntax:
Example:
<html >
<head>
<title>Open New Window</title>
<script >
function OpenNewWindow() {
MyWindow = window.open(‘webpage1.html’, 'myAdWin', 'status=0, toolbar=0,
location=0,
menubar=0, directories=0, resizable=0, height=250, width=250')
}
</script>
</head>
<body>
<FORM action=" " method="post">
<INPUT name="OpenWindow" value="Open Window" type="button"
onclick="OpenNewWindow()"/>
</FORM>
</body>
</html>
Page 12 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Example:
<html>
<body>
<script>
function myFunction() {
// input string
var str = "Good Morning!";
document.write(n + '<br>');
document.write(n);
}
myFunction();
</script>
</body>
</html>
b List ways of protecting your web page and describe any one of them. 4M
Ans Ways of protecting Web Page: List: 1 M
Page 13 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
The source code for your web page—including your JavaScript—is stored in the
cache, the part of computer memory where the browser stores web pages that
were requested by the visitor. A sophisticated visitor can access the cache and
thereby gain access to the web page source code.
However, you can place obstacles in the way of a potential peeker. First, you can
disable use of the right mouse button on your site so the visitor can't access the
View Source menu option on the context menu. This hides both your HTML code
and your JavaScript from the visitor.
Nevertheless, the visitor can still use the View menu's Source option to display
your source code. In addition, you can store your JavaScript on your web server
instead of building it into your web page. The browser calls the JavaScript from
the web server when it is needed by your web page.
Using this method, the JavaScript isn't visible to the visitor, even if the visitor
views the source code for the web page.
The following example shows you how to disable the visitor's right mouse button
while the browser displays your web page. All the action occurs in the JavaScript
that is defined in the <head> tag of the web page.
Example:
<html>
<head>
<title>Lockout Right Mouse Button</title>
<script language=JavaScript>
function BreakInDetected(){
alert('Security Violation')
return false
}
function NetscapeBrowser(e){
if (document.layers||
document.getElementById&&!document.all){
if (e.which==2||e.which==3){
Page 14 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
BreakInDetected()
return false
}
}
}
function InternetExploreBrowser(){
if (event.button==2){
BreakInDetected()
return false
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN)
document.onmousedown=NetscapeBrowser()
}
else if (document.all&&!document.getElementById){
document.onmousedown=InternetExploreBrowser()
}
document.oncontextmenu=new Function(
"BreakInDetected();return false")
</script>
</head>
<body>
<table width="100%" border=0>
<tbody>
<tr vAlign=top>
<td width=50>
<a>
<ing height=92 src="rose.jpg"
width=70 border=0
onmouseover="src='rose1.jpg'"
onmouseout="src='rose.jpg'">
</a>
</td>
<td>
<img height=1 src="" width=10>
</td>
<td>
<a>
<cTypeface:Bold><u> Rose Flower</U></b>
</a>
</font><font face="arial, helvetica, sans-serif"
size=-1><BR>Rose Flower
Page 15 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
</td>
</tr>
</tbody>
</table>
</body>
</html>
3) Hiding JavaScript
<script src="MyJavaScripts.js"
language="Javascript" type="text/javascript">
Next, you need to defi ne empty functions for each function that you define in the
external JavaScript fi le.
<html >
<head>
<title>Using External JavaScript File</title>
<script src="myJavaScript.js" language="Javascript" type="text/javascript">
function OpenNewWindow(book) {
}
</script>
</head>
<body>
<tablewidth="100%" border=0>
<tbody>
<tr vAlign=top>
<td width=50>
<a>
<img height=92 src="rose.jpg" width=70 border=0 name='cover'>
</a>
Page 16 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
</td>
<td>
<img height=1 src="" width=10>
</td>
<td>
<a onmouseover="OpenNewWindow(1)" onmouseout="MyWindow.close()">
<b><u>Rose </u></b>
</a>
<br>
<a onmouseover="OpenNewWindow(2)" onmouseout="MyWindow.close()">
<b><u>Sunflower</U></b>
</a>
<br>
<A onmouseover="OpenNewWindow(3)" onmouseout="MyWindow.close()">
<b><u>Jasmine </u></b>
</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
The final step is to create the external JavaScript fi le. You do this by placing all
function definitions into a new fi le and then saving the fi le using the .js
extension.
MyJavaScript.js file:
function OpenNewWindow(book) {
if (book== 1)
{
document.cover.src='rose.jpg'
MyWindow = window.open('', 'myAdWin', 'titlebar=0 status=0, toolbar=0,
location=0, menubar=0, directories=0, resizable=0, height=50,
width=150,left=500,top=400')
MyWindow.document.write( 'Rose flower')
}
if (book== 2)
{
document.cover.src='sunflower.jpeg'
MyWindow = window.open('', 'myAdWin', 'titlebar=0 status=0, toolbar=0,
location=0, menubar=0, directories=0, resizable=0, height=50,
width=150,left=500,top=500')
MyWindow.document.write( 'sunflower flower')
}
Page 17 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
if (book== 3)
{
document.cover.src='jasmine.gif'
MyWindow = window.open('', 'myAdWin', 'titlebar=0
status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0,
height=50,
width=150,left=500,top=600')
MyWindow.document.write( 'Jasmine Flower')
}
}
After you create the external JavaScript fi le, defi ne empty functions for each
function that is contained in the external JavaScript fi le, and reference the
external
JavaScript fi le in the src attribute of the <script> tag, you're all set.
Many of us have endured spam at some point and have probably blamed every
merchant we ever patronized for selling our e-mail address to spammers. While
e-mail addresses are commodities, it's likely that we ourselves are the culprits
who invited spammers to steal our e-mail addresses.
Here's what happens: Some spammers create programs called bots that surf the
Net looking for e-mail addresses that are embedded into web pages, such as those
placed there by developers to enable visitors to contact them. The bots then strip
these e-mail addresses from the web page and store them for use in a spam attack.
This technique places developers between a rock and a hard place. If they place
their e-mail addresses on the web page, they might get slammed by spammers. If
they don't display their e-mail addresses, visitors will not be able to get in touch
with the developers.
The solution to this common problem is to conceal your e-mail address in the
source code of your web page so that bots can't fi nd it but so that it still appears
on the web page. Typically, bots identify e-mail addresses in two ways: by the
mailto: attribute that tells the browser the e-mail address to use when the visitor
wants to respond to the web page, and by the @ sign that is required of all e-mail
addresses. Your job is to confuse the bots by using a JavaScript to generate the
e-mail address dynamically. However, you'll still need to conceal the e-mail
address in your JavaScript, unless the JavaScript is contained in an external
JavaScript file, because a bot can easily recognize the mailto: attribute and the @
sign in a JavaScript.
Bots can also easily recognize when an external fi le is referenced. To conceal an
e-mail address, you need to create strings that contain part of the e-mail address
and then build a JavaScript that assembles those strings into the e-mail address,
which is then written to the web page.
The following example illustrates one of many ways to conceal an e-mail address.
Page 18 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
It also shows you how to write the subject line of the e-mail. We begin by
creating four strings:
• The first string contains the addressee and the domain along with symbols &, *,
and _ (underscore) to confuse the bot.
• The second and third strings contain portions of the mailto: attribute name.
Remember that the bot is likely looking for mailto:.
• The fourth string contains the subject line. As you'll recall from your HTML
training, you can generate the TO, CC, BCC, subject, and body of an e-mail from
within a web page.
You then use these four strings to build the e-mail address. This process starts by
using the replace() method of the string object to replace the & with the @ sign
and the * with a period (.). The underscores are replaced with nothing, which is
the
same as simply removing the underscores from the string.
All the strings are then concatenated and assigned to the variable b, which is then
assigned the location attribute of the window object. This calls the e-mail program
on the visitor's computer and populates the TO and Subject lines with the strings
generated by the JavaScript.
<html>
<head>
<title>Conceal Email Address</title>
<script>
function CreateEmailAddress(){
var x = manish*c_o_m'
var y = 'mai'
var z = 'lto'
var s = '?subject=Customer Inquiry'
x = x.replace('&','@')
x = x.replace('*','.')
x = x.replace('_','')
x = x.replace('_','')
var b = y + z +':'+ x + s
window.location=b
}
-->
</script>
</head>
<body>
<input type="button" value="Help"
onclick="CreateEmailAddress()">
</body>
</html>
Page 19 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
c Create a slideshow with the group of three images, also simulate next and 4M
previous transition between slides in your Java Script.
Ans <html> Correct
<head> program: 4
<script> M
pics = new Array('1.jpg' , '2.jpg' , '3.jpg');
count = 0; (Any other
function slideshow(status) example can
{ be
if (document.images) considered)
{
count = count + status;
if (count > (pics.length - 1))
{
count = 0;
}
if (count < 0)
{
count = pics.length - 1;
}
documet.imag1.src = pics[count];
}
}
</script>
</head>
<body>
<img src="1.jpg" width="200" name="img1">
<br>
<input type="button" value="Next" onclick="slideshow(1)">
<input type="button" value="Back" onclick="slideshow(-1)">
</body>
</html>
d Explain text rollover with suitable example. 4M
Ans You create a rollover for text by using the onmouseover attribute of the <A> tag, Explanation:
which is the anchor tag. You assign the action to the onmouseover attribute the 2M
same way as you do with an <IMG> tag. Program: 2
Let's start a rollover project that displays a flower titles. Additional information M
about a flower can be displayed when the user rolls the mouse cursor over the
flower name. In this example, the image of the flower is displayed. However, (Any other
you could replace the flower image with an advertisement or another message example can
that you want to show about the flower. be
considered)
<html>
<head>
<title>Rollover Text</title>
Page 20 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
</head>
<body>
<TABLE width="100%" border="0">
<TBODY>
<TR vAlign="top">
<TD width="50">
<a>
<IMG height="92" src="rose.jpg"
width="70" border="0" name="cover">
</a>
</TD>
<TD>
<IMG height="1" src="" width="10">
</TD>
<TD>
<A onmouseover= "document.cover.src='sunflower.jpg'">
<B><U>Sunflower</U></B>
</A>
<BR>
<A onmouseover=
"document.cover.src='jasmine.jpg'">
<B><U>Jasmine</U></B>
</A>
<BR>
<A onmouseover=
"document.cover.src='rose.jpg'">
<B><U>Rose</U></B>
</A>
</TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
e Write a Java script to modify the status bar using on MouseOver and on 4M
MouseOut with links. When the user moves his mouse over the links, 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 <html> Correct
<head> program: 4
<title>JavaScript Status Bar</title></head> M
<body>
<a href=" https://msbte.org.in/"
onMouseOver="window.status='MSBTE';return true"
onMouseOut="window.status='';return true">
Page 21 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
MSBTE
</a>
</body>
</html>
Page 22 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 23 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Storing Cookies
The simplest way to create a cookie is to assign a string value to the
document.cookie object, which looks like this.
document.cookie = "key1 = value1;key2 = value2;expires = date";
Here the expires attribute is optional. If you provide this attribute with a valid
date or time, then the cookie will expire on a given date or time and thereafter,
the cookies' value will not be accessible.
<html>
<head>
<script type = "text/javascript">
<!--
function WriteCookie()
{
if( document.myform.customer.value == "" ) {
alert("Enter some value!");
return;
}
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie="name=" + cookievalue;
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name = "myform" action = "">
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onclick = "WriteCookie();"/>
</form>
</body>
</html>
Reading Cookies
Reading a cookie is just as simple as writing one, because the value of the
document.cookie object is the cookie. So you can use this string whenever you
want to access the cookie. The document.cookie string will keep a list of
name=value pairs separated by semicolons, where name is the name of a cookie
and value is its string value.
Page 24 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
You can use strings' split() function to break a string into key and values as
follows:-
<html>
<head>
<script type = "text/javascript">
<!--
function ReadCookie()
{
var allcookies = document.cookie;
document.write ("All Cookies : " + allcookies )
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
</head>
<body>
Page 25 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
</body>
</html>
c Write a java script that displays textboxes for accepting name & email ID & 6M
a submit button. Write java script code such that when the user clicks on
submit button
(1) Name Validation
(2) Email ID Validation.
Ans <html> Correct
<head> Html code:
<title>Form Validation</title> 2M
</head>
<body> Correct
<form action = "/cgi-bin/test.cgi" name = "myForm" onsubmit = Script code:
"return(validate());"> 4M
<table cellspacing = "2" cellpadding = "2" border = "1">
(Any other
<tr>
example can
<td align = "right">Name</td>
be
<td><input type = "text" name = "Name" /></td>
considered)
</tr>
<tr>
<td align = "right">EMail</td>
<td><input type = "text" name = "EMail" /></td>
</tr>
<tr>
<td align = "right"></td>
<td><input type = "submit" value = "Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
<script type = "text/javascript">
<!--
// Form validation code will come here.
function validate() {
if( document.myForm.Name.value == "" ) {
alert( "Please provide your name!" );
document.myForm.Name.focus() ;
return false;
}
if( document.myForm.EMail.value == "" ) {
Page 26 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 27 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
}
if(b.checked == true)
{
x+= b.value+ " ";
}
if(o.checked == true)
{
x+= o.value+ " ";
}
if(p.checked == true)
{
x+= p.value+ " ";
}
if(g.checked == true)
{
x+= g.value+ " ";
}
document.write(x);
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Fruits: <br>
<input type="checkbox" name="a" value="Apple">Apple
<input type="checkbox" name="b" value="Banana">Banana
<input type="checkbox" name="o" value="Orange">Orange
<input type="checkbox" name="p" value="Pear">Pear
<input type="checkbox" name="g" value="Grapes">Grapes
<input type="reset" value="Show" onclick="selection()">
</form>
</body>
</html>
</form>
</body>
</html>
Page 28 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 29 |3 0
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 30 |3 0
21222
22519
3 Hours / 70 Marks Seat No.
15 minutes extra for each hour
Marks
(c) Write a javascript program to check whether entered number is prime or not.
(i) onmouseup
(ii) onblur
[1 of 4] P.T.O.
22519 [2 of 4]
2. Attempt any THREE of the following : 12
(a) Write a javascript program to validate user accounts for multiple set of user
ID and password (using swith case statement).
(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.
(a) Write a javascript program to create read, update and delete cookies.
(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.
(d) State what is regular expression. Explain its meaning with the help of a
suitable example.
(b) Write a javascript function that accepts a string as a parameter and find the
length of the string.
(c) Write a javascript program to validate email ID of the user using regular
expression.
22519 [3 of 4]
(d) Write a javascript program to design HTML page with books information in
tabular format, use rollovers to display the discount information.
(e) List ways of protecting your webpage and describe any one of them.
(b) Develop javascript to convert the given character to unicode and vice-versa.
(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.
(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.
(b) Write a javascript to create option list containing list of images and then
display images in new window as per selection.
(c) Write a javascript function to generate Fibonacci series till user defined limit.
____________
P.T.O.
22519 [4 of 4]
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2022 EXAMINATION
Subject Name: Client-Side Scripting Model Ans Subject Code: 22519
Important Instructions to examiners: XXXXX
1) The answers should be examined by key words and not as word-to-word as given in the model answer
scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not
applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The
figures drawn by candidate and model answer may vary. The examiner may give credit for any equivalent
figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may
vary and there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based
on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual
(English + Marathi) medium is introduced at first year of AICTE diploma Programme from academic year
2021-2022. Hence if the students in first year (first and second semesters) write answers in Marathi or
bilingual language (English +Marathi), the Examiner shall consider the same and assess the answer based
on matching of concepts with model answer.
a) State the use of method in javascript with the help of suitable example. 2M
Ans A method/function is a set of statements that take inputs, do some specific computation, Explanation
and produce output. The idea is to put some commonly or repeatedly done tasks together - 1 M and
and make a function so that instead of writing the same code again and again for different Example-
1 M.
inputs, we can call that function.
Example:
function Addition (number1, number2)
{
return number1 + number2;
}
b) List & Explain datatypes in JavaScript. 2M
Ans JavaScript provides different data types to hold different types of values. There are two Any four,
types of data types in JavaScript, Primitive data type and Non-primitive data type ½ for each
i) There are five types of primitive data types in JavaScript. They are as follows:
String - represents sequence of characters e.g., "hello"
Number - represents numeric values e.g., 100
Page No: 1 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Boolean - represents boolean value either false or true
Undefined - represents undefined value
Null - represents null i.e., no value at all
switch (operator) {
case "+":
result = number1 + number2;
document.write(result);
break;
case "-":
result = number1 - number2;
document.write(result);
break;
case "*":
result = number1 * number2;
document.write(result);
break;
case "/":
result = number1 / number2;
document.write(result);
break;
case "%":
result = number1 % number2;
document.write(result);
break;
Page No: 2 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
default:
document.write("Invalid operator");
break;
}
</script>
</body>
</html>
d) Write a program using sort method of array object. 2M
Ans JavaScript object accessors are used to access and update the objects. Getter and setter are 1 m for each
used as object accessors to get or set object properties.
Using getter and setter the javascript provides better data security and data quality.
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var car = {
brand: "Toyota",
color: "Blue",
get getBrand () {
return this.brand;
},
get getColor () {
return this.color;
Page No: 3 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
},
car.setBrand = "Tesla";
car.setColor = "Red";
document.write("<br><br>Car Brand: " + car.brand + "<br>Car Color: " +
car.color);
</script>
</body>
</html>
f) Enlist & explain the use of any two Intrinsic JavaScript Functions. 2M
Ans An intrinsic function (or built-in function) is a function (subroutine) available for use in a 1 M for
given programming language whose implementation is handled specially by the compiler. each
You can use intrinsic functions to make reference to a data item whose value is derived function
automatically during execution.
abs() - The ABS function returns the absolute value of the argument.
sin() - The SIN function returns a numeric value that approximates the sine of the angle or
arc specified by the argument in radians.
sqrt() - The SQRT function returns a numeric value that approximates the square root of
the argument specified.
Page No: 4 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans i) The location object contains information about the current URL. Explanation
ii) The location object is a property of the window object. 1M
iii) The location object is accessed with: window.location or just location. Example-
Example: 1M
<!DOCTYPE html>
<html>
<body>
<h1>The Window Location Object</h1>
<p id="demo"></p>
<script>
let origin = window.location.origin;
document.getElementById("demo").innerHTML = origin;
</script>
</body>
</html>
a) Write a JavaScript program that will display current date in DD/MM/YYYY format. 4M
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var currentDate=d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear()
document.write(currentDate)
Page No: 5 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
</script>
</body>
</html>
b) Write a JavaScript program that will remove the duplicate element from an array. 4M
<script>
var Avgmarks = 0;
Page No: 6 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Avgmarks += students[i][1];
a = students[i];
students[i] = students[j];
students[j] = a
document.write("<br><br>");
document.write(students[i]+"<br>")
</script>
</body>
</html>
d) Write and explain a string functions for converting string to number and number to 4M
string.
Ans To covert string to number we can use parseInt() which converts a string number to a Any
integer number. Similarly we can use parseFloat(), number() for converting string to relevant
number. code with
explanation
Eg- 4 M.
var a=prompt('Enter a number');
var b=parseInt(prompt('Enter a number'));
document.write(typeof a+"<br>");
document.write(typeof b);
To convert form number to string we can use toString()
<html>
Page No: 7 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<body>
<p>toString() returns a number as a string:</p>
<script>
let num = 12;
let text = num.toString();
document.write(num)
</script>
</body>
</html>
Ans Any 4
concat() join() point=4M
The concat() method concatenates (joins) two The join() method returns an array as
or more arrays. a string.
The concat() method returns a new array,
containing the joined arrays.
The concat() method separates each value with Any separator can be specified. The
a comma only. default is comma (,).
Syntax: Syntax:
array1.concat(array2, array3, ..., arrayX) array.join(separator)
Example: Example:
<script> <script>
const arr1 = ["CO", "IF"]; var fruits = ["Banana", "Orange",
const arr2 = ["CM", "AI",4]; "Apple", "Mango"];
const arr = arr1.concat(arr1, arr2); var text = fruits.join();
document.write(arr); document.write(text);
</script> var text1 = fruits.join("$$");
document.write("<br>"+text1);
</script>
OR
<script>
function firstIsUppercase(str)
{
if (str.length === 0)
{
return false;
}
if (firstIsUppercase(prompt("Enter text")))
{
document.write('First letter is uppercase');
} else {
document.write('First letter is NOT uppercase');
}
</script>
c) Write a JavaScript function to merge two array & removes all duplicate 4M
values.
Ans <html> Correct
<body> function
<script> logic=4 M
function merge_array(array1, array2)
{
var result_array = []; (any other
relevant
var arr = array1.concat(array2);
logic can
var len = arr.length; consider)
var assoc = {};
Page No: 9 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
while(len--)
{
var item = arr[len];
if(!assoc[item])
{
result_array.unshift(item);
assoc[item] = true;
}
}
return result_array;
}
var array1 = [1, 2, 3,4,7,9];
var array2 = [2, 30, 1,40,9];
document.write(merge_array(array1, array2));
</script>
</body>
</html>
Output:
3,4,7,2,30,1,40,9
OR
<html>
<body>
<script>
function mergearr(arr1, arr2)
{
// merge two arrays
var arr = arr1.concat(arr2);
var uniqueArr = [];
// loop through array
for(var i of arr) {
if(uniqueArr.indexOf(i) === -1)
{
uniqueArr.push(i);
}
}
document.write(uniqueArr);
}
Page No: 10 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
var array1 = [1, 2, 3,6,8];
var array2 = [2, 3, 5,56,78,3]
mergearr(array1, array2);
</script>
</body>
</html>
Output:
1,2,3,6,8,5,56,78
d) Write a JavaScript function that will open new window when the user will 4M
clicks on the button.
Ans <html> Correct
<body> function
<button onclick="openWin()">Open "New Window"</button> logic=4 M
<script>
var myWindow;
function openWin()
{
myWindow = window.open("", "myWindow", "width=400,height=400");
myWindow.document.write("<p>Hello Everyone.Welcome to new window.</p>");
}
</script>
</body>
</html>
Ans Rollover means a webpage changes when the user moves his or her mouse over an object Define
on the page. It is often used in advertising. There are two ways to create rollover, using Rollover-2
plain HTML or using a mixture of JavaScript and HTML. We will demonstrate the creation M
of rollovers using both methods.
Page No: 11 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The HTML script is shown in the following example: logic can be
considered)
Example:
<html>
<head></head>
<Body>
<textarea rows="2" cols="50" name="rollovertext" onmouseover="this.value='What
is rollover?'"
onmouseout="this.value='Rollover means a webpage changes when the user moves
his or her mouse over an object on the page'"></textarea>
</body>
</html>
b) Write a JavaScript program that will create pull-down menu with three 4M
options. Once the user will select the one of the options then user will redirected
to that website.
Page No: 12 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Output:
Ans The frequency or position of bracketed character sequences and single characters can be Describe
denoted by a special character. Each special character has a specific connotation. Quantifiers-
The +, *, ?, and $ flags all follow a character sequence. 2M
For
Sr.No. Expression & Description
Example-2
p+ M
1
It matches any string containing one or more p's.
p*
2
It matches any string containing zero or more p's.
p?
3
It matches any string containing at most one p.(zero or one occurrences)
p{N}
4
It matches any string containing a sequence of N p's
p{2,3}
5
It matches any string containing a sequence of two or three p's.
p{2, }
6
It matches any string containing a sequence of at least two p's.
p$
7
It matches any string with p at the end of it.
Example:
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
var str = "100, 1000 or 10000?";
var patt1 = /\d{3,4}/g;
Page No: 13 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
var result = str.match(patt1);
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
d) Describe frameworks of JavaScript & its application. 4M
Applications:
React is a JavaScript library developed by Facebook which, among other things, was used
to build Instagram.com.
2. Angular
Google operates this framework and is designed to use it to develop a Single Page
Application (SPA). This development framework is known primarily because it gives
developers the best conditions to combine JavaScript with HTML and CSS. Google
operates this framework and is designed to use it to develop a Single Page Application
(SPA). This development framework is known primarily because it gives developers the
best conditions to combine JavaScript with HTML and CSS.
Applications:
Microsoft Office ,Gmail, Forbes, PayPal, Grasshopper, Samsung, Delta
3. Vue.js
Vue is an open-source JavaScript framework for creating a creative UI. The integration
with Vue in projects using other JavaScript libraries is simplified because it is designed to
be adaptable.
Application:
VueJS is primarily used to build web interfaces and one-page applications. It can also
be applied to both desktop and mobile app development.
4. jQuery
It is a cross-platform JavaScript library designed to simplify HTML client-side scripting.
You can use the jQuery API to handle, animate, and manipulate an event in an HTML
document, also known as DOM. Also, jQuery is used with Angular and React App building
tools.
Applications:
1. JQuery can be used to develop Ajax based applications.
2. It can be used to make code simple, concise and reusable.
3. It simplifies the process of traversal of HTML DOM tree.
4. It can also handle events, perform animation and add ajax support in web applications.
Page No: 14 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
5. Node.js
Node.js is an open-source, server-side platform built on the Google Chrome JavaScript
Engine. Node.js is an asynchronous, single-threaded, non-blocking I/O model that makes
it lightweight and efficient.
Applications:
Paypal, LinkedIn, Yahoo, Mozilla, Netflix, Uber, Groupon, GoDaddy, eBay
Ans The banner advertisement is the hallmark of every commercial web page. It is typically Banner-1 M
positioned near the top of the web page, and its purpose is to get the visitor's attention by Example-3
doing all sorts of clever things. M
To get additional information, the visitor is expected to click the banner so that a new web
page opens. You can link a banner advertisement to a web page by inserting a hyperlink
into your web page that calls a JavaScript function rather than the URL of a web page. The
JavaScript then determines the URL that is associated with the current banner and loads the
web page that is associated with the URL.
Example:
<html>
<head>
<title>Link Banner Ads</title>
<script language="Javascript" type="text/javascript">
Banners = new Array('1.jpg','2.jpg','3.jpg')
BannerLink = new Array(
'google.com/','vpt.edu.in/', 'msbte.org.in/');
CurrentBanner = 0;
NumOfBanners = Banners.length;
function LinkBanner()
{
document.location.href =
"http://www." + BannerLink[CurrentBanner];
}
function DisplayBanners() {
if (document.images) {
CurrentBanner++
if (CurrentBanner == NumOfBanners) {
CurrentBanner = 0
}
document.RotateBanner.src= Banners[CurrentBanner]
setTimeout("DisplayBanners()",1000)
}
}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<a href="javascript: LinkBanner()"><img src="1.jpg"
Page No: 15 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
width="400" height="75" name="RotateBanner" /></a>
</center>
</body> </html>
Page No: 16 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<td>Pin code : </td>
<td> <input type="number" id="pin" required></td>
</tr>
<tr>
<td></td>
<td><button onclick="submit()">Submit</button></td>
</tr>
</tbody>
</table>
</body>
<script>
function submit()
{
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var pin = Number(document.getElementById("pin").value);
if(name.length==0 || email.length==0 || pin.length==0)
{
alert("Please enter value in all fields.")
}
else
{
var pinpattern =/^[4]{1}[0-9]{5}$/;
if( pinpattern.test(pin))
{
alert("Perfect Pin code");
}
else
{
alert("Wrong Pin code.");
}
}
}
</script>
</html>
b) Write a webpage that displays a form that contains an input for user name and 6M
password. User is prompted to enter the input user name and password and password
becomes the value of the cookie. Write the JavaScript function for storing the cookies.
It gets executed when the password changes.
Ans <html> Creation of
<head> form=2 M
<script> Storing and
function storeCookie() display
{ cookie
var pwd = document.getElementById('pwd').value information-
document.cookie = "Password=" + pwd + ";" 4M
Page No: 17 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
alert("Cookie Stored\n"+document.cookie);
}
</script>
</head>
<body>
<form name="myForm">
Enter Username <input type="text" id="uname"/><br/>
Enter Password <input type="password" id="pwd"/><br/>
<input type="button" value="Submit" onclick="storeCookie()"/>
<p id="panel"></p>
</form>
</body>
</html>
Chapter 1 and Chapter 2 are linked to the webpage Ch1.html and ch2.html
respectively. When user click on these links corresponding data appears in
FRAME3.
Ans Step 1) create file frame1.html Correct
<html> frameset
<body> logic=6 M
<h1 align="center">FRAME1</h1>
</body>
</html> OR
( any other
relevant
Step 2) create frame2.html
logic can be
<html> considered )
<head>
<title>FRAME 2</title>
</head>
<body><H1>Operating System</H1>
<a href="Ch1.html" target="c"><UL>Chapter 1</UL></a>
<br>
<a href=" Ch2.html" target="c"><UL> Chapter 2</UL></a>
</body>
</html>
Page No: 18 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Step 3) create frame3.html
<html>
<body>
<h1>FRAME3</h1>
</body>
</html>
Output:
a) Write HTML script that will display dropdown list containing options such as 6M
Red, Green, Blue and Yellow. Write a JavaScript program such that when the
user selects any options. It will change the background colour of webpage.
Page No: 19 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans <html> Creation of
<body> list-2 M
<label for="color">Choose a Background Color:</label>
<select name="color" id="color" class="color" onchange="changeColor()"> Correct
<option value="red">Red</option> logic to
<option value="green">Green</option> Change
<option value="blue">Blue</option> background
<option value="yellow">Yellow</option> color as per
</select> selection-4
<script type="text/javascript"> M
function changeColor() {
var color = document.getElementById("color").value;
switch(color){
case "green":
document.body.style.backgroundColor = "green";
break;
case "red":
document.body.style.backgroundColor = "red";
break;
case "blue":
document.body.style.backgroundColor = "blue";
break;
case "yellow":
document.body.style.backgroundColor = "yellow";
break;
default:
document.body.style.backgroundColor = "white";
break;
}
}
</script>
</body>
</html>
b) Develop a JavaScript program to create Rotating Banner Ads. 6M
Page No: 20 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
}
}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<img src="1.jpg" width="400"
height="75" name="RotateBanner" />
</center>
</body>
</html>
.caret-down::before {
-ms-transform: rotate(90deg); /* IE 9 */
-webkit-transform: rotate(90deg); /* Safari */'
transform: rotate(90deg);
}
.nested {
display: none;
}
.active {
display: block;
}
</style>
</head>
<body>
<ul id="myUL">
<li><span class="caret">India</span>
<ul class="nested">
<li>Karnataka</li>
<li>Tamilnaadu</li>
<li><span class="caret">Maharashtra</span>
<ul class="nested">
<li>Mumbai</li>
<li>Pune</li>
<li><span class="caret">Navi Mumbai</span>
<ul class="nested">
<li>Nerul</li>
<li>Vashi</li>
<li>Panvel</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<script>
var toggler = document.getElementsByClassName("caret");
var i;
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".nested").classList.toggle("active");
this.classList.toggle("caret-down");
});
}
</script>
</body>
</html>
Page No: 22 | 22
22232
22519
3 Hours / 70 Marks Seat No.
Marks
[1 of 4] P.T.O.
22519 [2 of 4]
(c) Write a JavaScript for loop that will iterate from 1 to 15. For each iteration, it
will check if the current number is odd or even and display a message to the
screen.
Sample Output :
“1 is odd”
“2 is even”
…………
………....
(d) Write the use of charCodeAt() and from CharCode() method with syntax and
example.
(a) Differentiate between push() and join() method of array object with respect to
use, syntax, return value and example.
(b) Write JavaScript code to perform following operations on string. (Use split()
method)
Display output as
(c) Explain splice() method of array object with syntax and example.
(d) Explain how to create and read Persistent Cookies in JavaScript with example.
22519 [3 of 4]
4. Attempt any THREE of the following : 12
(a) Explain test() and exec() method of Regular Expression object with example.
(b) List ways of protecting your web page and describe any one of them.
(c) Explain how to create and display Rotating Banner in JavaScript with
example.
(e) What is Status bar and how to display moving message on the status line of a
window using JavaScript ?
(a) Write HTML code to design a form that displays two textboxes for accepting
two numbers, one textbox for accepting result and two buttons as ADDITION
and SUBTRACTION. Write proper JavaScript such that when the user clicks
on any one of the button, respective operation will be performed on two
numbers and result will be displayed in result textbox.
(b) Write HTML code to design a form that displays two buttons START and
STOP. Write a JavaScript code such that when user clicks on START button,
real time digital clock will be displayed on screen. When user clicks on STOP
button, clock will stop displaying time. (Use Timer methods)
(c) Write HTML code to design a form that displays textboxes for accepting
UserID and Aadhar No. and a SUBMIT button. UserID should contain 10
alphanumeric characters and must start with Capital Letter. Aadhar No.
should contain 12 digits in the format nnnn nnnn nnnn. Write JavaScript code
to validate the UserID and Aadhar No. when the user clicks on SUBMIT
button.
P.T.O.
22519 [4 of 4]
6. Attempt any TWO of the following : 12
Frame 1 contains three buttons SPORT, MUSIC and DANCE that will
perform following action :
When user clicks SPORT button, sport.html webpage will appear in Frame 2.
When user clicks MUSIC button,music.html webpage will appear in Frame 3.
When user clicks DANCE button,dance.html webpage will appear in Frame 4.
FRAME 1
(Fig. 1)
(c) Write a JavaScript to create a pull – down menu with four options [AICTE,
DTE, MSBTE, GOOGLE]. Once the user will select one of the options then
user will be redirected to that site.
_______________
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2023 EXAMINATION
Model Answer – Only for the Use of RAC Assessors
Ans (i) ++ is the increment operator and a is the operand, hence a++ will increment the Anyone
value of a by 1. explained - 1
M each.
(ii) The bgColor property specifies the background color of HTML document.
b) Write and explain syntax of prompt( ) method in JavaScript. 2M
Ans prompt() method is used to display a dialogue box to the user to prompt them to Definition- 1
an input. M
It has two buttons “OK” and “CANCEL”, if the user click on the “OK” button Syntax- 1 M
then it will return the inputed value , if the user clicks on the "CANCEL” button
then it will return a null value
Syntax: prompt(text)
Page No: 1 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Example:
<script>
var name = prompt ("Enter a name");
document. Write(name);
</script>
c) List various assignment operators supported by JavaScript, explain any 2M
two with the help of suitable example.
Ans assignment operators supported by JavaScript List – 1 M
Operators Meaning Explain any 2
= Equal to -1M
+= Plus Equal to
-= Minus Equal to
/= Divide Equal to
%= Modulus Equal to
*= Multiply Equal to
Example:
<script>
// = is used to assign a value to a variable
var num = 10;
document.write(num); // num 10
/* += first add the value to the existing value of the variable then assign it the new added
value */
num +=10; document.write(num); // num 20
</script>
d) Differentiate between shift() and push() methods of an Array object. 2M
Page No: 2 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
e) State the meaning of "Defining a function". Explain with the help of an example. 2M
Ans A function is a block of code that takes some input to perform some certain Explanation-
computation. 1M
The main purpose of the function is to put commonly used or repeatedly used Example- 1
task in a function, so instead of writing the code again and again we can call it M
instead.
Syntax:
function func_name(parameter1 ,parameter2,…,parametern)
{
//code
}
Example:
<script>
function add(num1,num2)
{
return num1 + num2;
}
add(1,2);
</script>
f) Give syntax of and explain the use of small “with” clause. 2M
Ans “with” clause is used to directly access the properties and method of an object. Explanation-
1M
Syntax:
with (object) Syntax- 1 M
{
//object
}
Example:
<script>
var person ={ name:"Abc", age:18
}
with(person){ docment.write(name); docment.write(age);
}
</script>
g) With the help of suitable example explain the Date object and any two methods of 2M
Date object.
Ans “Date” object is used when we want to perform some operation on date, it has various Explanation-
method which helps you performs some task related to date, 1M
Example: Example- 1
Page No: 3 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<script> M
var date = new Date();
document.write(date.getDate()); // get the current date
document.write(date.getFullYear()); // get the current Year
document.write(date.getMinutes()); // get the current minutes
</script>
Page No: 4 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
</body>
</html>
c) Give syntax of and explain for-in loop in javascript with the help of suitable 4M
example.
Page No: 5 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
</script>
</body>
</html>
OR
<html>
<head>
<script>
function interest()
{
var P, N, R;
P= parseInt(document.getElementById("pr").value);
N = parseInt(document.getElementById("period").value);
R = parseInt(document.getElementById("ri").value);
var SI =(P*N*R)/100;
alert("Simple Interest is="+SI);
}
</script>
</head>
<body>
<p>Principal Amount:<input id="pr"></p>
<p>Period in Year: <input id="period"></p>
<p>Rate of Interst: <input id="ri"></p>
<button onclick="interest()"> Simple Interest</button>
</body>
</html>
Output:
Page No: 6 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
3. Attempt any THREE of the following: 12 M
a) Write an HTML Script that displays the following webpage output: Designing
and calling
function in
onClick() -
1M
Writing
function for
add,sub,mul-
03M
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 <html>
<head>
<script>
function add()
{
var num1, num2, r;
//to accept 2 values and stored in variable num1 and num2
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
r= num1 + num2;
alert(r);
}
function sub()
{
var num1, num2, r;
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
Page No: 7 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
r = num1 - num2;
alert(r);
}
function mul()
{
var num1, num2, r;
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
r = num1 * num2;
alert(r);
}
</script>
</head>
<body>
<fieldset>
<p>First Number: <input id="firstnumber"></p>
<p>Second Number: <input id="secondnumber"></p>
//onClick() event to perform addition, subtraction and multiplication
<button onclick="add()">Add</button>
<button onclick="sub()">Sub</button>
<button onclick="mul()">Mul</button>
</fieldset>
</body>
</html>
Output:
Page No: 8 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
b) Write a JavaScript that accents user's first name and domain name of 4M
Organization from user., The JavaScript then forms email address as
<firstname@domain> name and displays the results in the browser window.
Page No: 9 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Output:
Example:
<script>
var a="Javascript";
document.write("Using substring()="+a.substring(2,6));
document.write("<br>Using substr()="+a.substr(2,6));
</script>
Output:
Using substring()=vasc
Using substr()=vascri
d) State what is a cookie? Explain its need. State characteristics of persistent 4M
cookies.
Page No: 10 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Cookie: Definition-1M
Cookies are small text files that websites use to store information on a user's computer
or device. Cookies can be used for a variety of purposes, such as remembering a user's Need-1M
preferences, tracking their behavior on a website, and enabling personalized advertising.
Charactristics-
There are two main types of cookies: session cookies and persistent cookies. 2M
Need of Cookie:
Cookies are built specifically for web browsers to track, personalize and save
information about each user's session. A “session” is the word used to define the amount
of time you spend on a site. Cookies are created to identify you when you visit a new
website.
Persistent cookies can be used to track a user's behavior on a website over time,
which can be used to personalize the user's experience.
a) Write a JavaScript that accepts a string and searches for the pattern 4M
"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".
Closed It returns the Boolean value indicating whether a window has been
closed or not.
calling
History It returns the history object for the window. onunload()-
1M
innerHeight It sets or returns the inner height of a window's content area.
innerWidth It sets or returns the inner width of a window's content area.
valid function
Length It returns the number of frames in a window.
definition-1M
Location It returns the location object for the window.
Name It sets or returns the name of a window.
Navigator It returns the navigator object for the window.
Opener It returns a reference to the window that created the window.
outerHeight It sets or returns the outer height of a window, including
toolbars/scrollbars.
outerWidth It sets or returns the outer width of a window, including
toolbars/scrollbars.
Parent It returns the parent window of the current window.
Screen It returns the screen object for the window.
screenX It returns the X coordinate of the window relative to the screen.
screenY It returns the Y coordinate of the window relative to the screen.
Self It returns the current window.
Status It sets the text in the status bar of a window.
Top It returns the topmost browser window that contains frames.
Page No: 12 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Code:
<html>
<body onload="openWin()" onunload = "myWindow.document.write("FUN WITH
SCRIPTING");">
<script>
var myWindow;
function openWin()
{
myWindow = window.open("", "myWindow", "width=200,height=100");
myWindow.document.write("<p>WELCOME TO SCRIPTING</p>");
}
function closeWin()
{
myWindow.close();
alert("Fun with SCripting");
}
</script>
</body>
</html>
Output:
c) Write an HTML script that displays names of different brands of Laptop and 4M
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 Code: Designing of
form-1M
<html>
<head> Any relevant
Page No: 13 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<title> logic-3M
text rollovers</title>
<script>
b=new Image;
r=new Image;
g=new Image;
if(document.images)
{
b.src='vv.png';
r.src='hp.png';
g.src='dell.png';
}
else
{
b.src='';
r.src='';
g.src='';
document.clr='';
}
</script>
</head>
<body>
<table border="0" width="100%">
<tbody>
<tr valign="top">
<td><H2><ul><li>
<a onmouseover="document.clr.src='vv.png'">
<b><u>Lenovo</u></b></a></li>
<li><a onmouseover="document.clr.src='hp.png'">
<b><u>HP</u></b></a></li>
<li><a onmouseover="document.clr.src='dell.png'">
<b><u>DELL</u></b></a></li></ul>
</H2>
</td>
<td width="50%">
<a><img height="200" src="vv.png" width=400" name="clr"></a></td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
When mouse over to HP, hp laptop image will displayed.
Page No: 14 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
d) Give syntax of and explain the use of SetTimeOut() function with the help of 4M
suitable example.
Ans
Use of setTimeout() Use of
SetTimeOut()-
The setTimeout() method executes a block of code after the specified time. The method 1M
executes the code only once.
Syntax-1M
The commonly used syntax of JavaScript setTimeout is: Example-2M
setTimeout(function, milliseconds);
<script>
function greet()
{
document.write('Hello world');
}
setTimeout(greet, 3000);
document.write('This message is shown first');
</script>
Page No: 15 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
In the above program, the setTimeout() method calls the greet() function after 3000
milliseconds (3 second).
Hence, the program displays the text Hello world only once after 3 seconds.
e) State the use of hiding the JavaScript. Explain the steps needed to accomplish it and 4M
describe the process.
Ans You can hide your JavaScript from a visitor by storing it in an external file on your web Use-2M
server. The external file should have the .js file extension. The browser then calls the
external file whenever the browser encounters a JavaScript element in the web page. If Steps with
you look at the source code for the web page, you'll see reference to the external .js file, code-2M
but you won't see the source code for the JavaScript.
webpage.html
<html>
<head>
<script src="mycode.js" languages="javascript" type="text/javascript">
</script>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
</html>
mycode.js
window.onload=function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
}
Output:
Page No: 17 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
i) Validation of email address.
(ddd) -(dddddddd)
var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;s
Page No: 18 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) 6M
if(x ==2)
{
optionList[0].text="Capaccino";
optionList[0].value=1;
Page No: 19 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
optionList[1].text="Latte";
optionList[1].value=2;
optionList[2].text="Expression";
optionList[2].value=3;
}
if(x ==3)
{
optionList[0].text="MAAZA";
optionList[0].value=1;
optionList[1].text="SPRITE";
optionList[1].value=2;
optionList[2].text="COKA-COLA";
optionList[2].value=3;
}
}
}
</script>
</head>
<body>
<form name="myform" action=" " method="post">
<table><tr><td>
Select Beverage: </td><td>
<input type="checkbox" name="grp1" value=1 checked="true"
onclick="modifyList(this.value)"> TEA
</td></tr></table>
<select name="optionList" size="3">
<option value=1>Kiwi
<option value=1>Pine-Apple
<option value=1>Apple
</tr> </table>
</select>
</form>
</body>
</html>
Output:
Page No: 20 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
b) Write a JavaScript that sets a crawling status bar message to the webpage. 6M
Message is "Welcome to the Mystic World of JavaScript". The message must
start crawling when the webpage gets loaded.
ii) List any three properties of regular expression objects and state their use.
Ans i) i) correct html
code-3M
Code:
ii) 3 properties
<html> with use-3M
<head> each
<title>Create a Frame</title>
</head>
<frameset rows="10%,*" border="5" frameborder="1" bordercolor="red" noresize>
<frame src="frame1.html">
<frameset cols="33%,33%,*" border="3">
<frame src="frame2.html">
<frame src="frame4.html">
Page No: 22 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<frame src="frame3.html">
</frameset>
</frameset>
</html>
ii)
ignoreCase
Specifies if the "i" modifier is set.
lastIndex
The index at which to start the next match.
multiline
Specifies if the "m" modifier is set.
source
The text of the pattern.
Example:
<html>
<head>
<title>JavaScript RegExp ignoreCase Property</title>
</head>
<body>
<script type = "text/javascript">
var re = new RegExp( "string" );
if ( re.ignoreCase )
{
Page No: 23 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
document.write("Test1-ignoreCase property is set");
} else
{
document.write("Test1-ignoreCase property is not set");
}
if ( re.ignoreCase )
{
document.write("<br/>Test2-ignoreCase property is set");
} else
{
document.write("<br/>Test2-ignoreCase property is not set");
}
</script>
</body>
</html>
Page No: 24 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 1 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 3 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 4 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 5 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
firstname: ‗abc‘,
get getname()
{
return this.firstname;
}
};
Example of setter
const student
{
firstname: ‗abc‘,
set changename(nm)
{
this.firstname=nm;
}
};
c) Write a JavaScript program to check whether a number is 4M
positive, negative or zero using switch case.
Ans. Note: Any other relevant logic shall be considered. Correct logic
2M
<html>
<body>
<script type="text/javascript"> Correct syntax
var num=prompt("Enter number"); 2M
switch (Math.sign(num))
{
case 1:
alert("The number is Positive");
break;
case -1:
alert("The number is Negative");
break;
default:
alert("The number is Zero");
}
</script>
</body>
</html>
Page 6 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Output: 97
Output: a
Page 7 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Here, the keys of the associative array are ―Company Name‖ & ―ID‖
whereas in the normal array. The keys or index is 0 & 1.
b) Write a JavaScript function that checks whether a passed string 4M
is palindrome or not.
Ans. Correct logic
Note: Any other relevant logic shall be considered 2M
function isPalindrome(str) {
str = str.replace(/[^A-Za-z0-9]/g, '').toLowerCase(); Correct syntax
2M
return str === str.split('').reverse().join('');
}
console.log(isPalindrome("A man, a plan, a canal, Panama")); //
Output: true
console.log(isPalindrome("racecar")); // Output: true
console.log(isPalindrome("hello")); // Output: false
Page 8 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Parameter:
•The first parameter defines the position where new elements should
be added (spliced in).
•The second parameter defines how many elements should be
removed.
•The list_of_elemnts_to_be_added parameter define the new
elements to be added(optional).
Page 9 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Explanation
window.location.href:
of location
Returns the complete URL of the current page. 2M
window.location.hostname:
Returns the domain name of the web server.
window.location.pathname:
Returns the path and filename of the current page.
window.location.protocol:
Returns the protocol (HTTP, HTTPS, etc.) of the current page.
window.location.assign(url):
Loads the specified URL.
window.location.reload(forceReload):
Reloads the current page.
// Example: Changing browser location
window.location.href = "https://example.com/page2";
Explanation
Window History of history 2M
The window.history object can be written without the window
prefix.
To protect the privacy of the users, there are limitations to how
JavaScript can access this object.
Some methods:
history.back() - same as clicking back in the browser
history.forward() - same as clicking forward in the browser
Window History Back
The history.back() method loads the previous URL in the history
list.
This is the same as clicking the Back button in the browser.
Example:
<html>
<head>
<script>
function goBack() {
window.history.back()
}
Page 10 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>
4. Attempt any THREE of the following: 12
a) State what is frame? Explain how it can be created with suitable 4M
example.
Ans. Note: Explanation of either <frameset> , <frame> or <iframe>
shall be considered. Definition
A frame refers to an HTML element that allows the display of 1M
another HTML document within the current web page. Frames are
Explanation
implemented using the <frameset>, <frame> and <iframe> (Inline with example
Frame) element in HTML. 3M
Attributes:
cols=”pixels/percentage” Specify number and size of
columns in a frameset. Default
value is 100% (1 column).
rows=”pixels/percentage” Specify number and size of rows in
a frameset. Default value is 100%
(1 row).
Page 11 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Attributes:
src=”URL” Specify address of a web page to be
displayed in a frame.
name=” string” Specify name of the frame which can
be used as target to open a link.
Code:
<html>
<frameset cols="25%,75%" >
<frame src="page1.html" name="f1">
<frame src="page2.html" name="f2">
</frameset>
</html>
OR
Creating Frames with <iframe> in HTML:
To create a frame using the <iframe> element, you specify the URL
of the document you want to embed as the value of the src attribute.
Cross-Origin Restrictions: When embedding content from external
sources, cross-origin restrictions may apply. This means that the
embedded content must be served with appropriate CORS (Cross-
Origin Resource Sharing) headers to allow it to be displayed within
the frame.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Frame Example</title>
<style>
/* Style the iframe */
iframe {
Page 12 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
width: 100%;
height: 300px; /* Set the height as desired */
border: 1px solid #ccc; /* Add a border for clarity */
}
</style>
</head>
<body>
<!-- Create a frame with an embedded document -->
<iframesrc="https://www.example.com"></iframe>
</body>
</html>
b) Explain the steps to create floating menu and chain select menu 4M
Ans. A floating menu is a menu that remains visible as the user scrolls
Correct steps
down a web page. It's often used for navigation or providing quick of each 2M
access to important content. Here's how you can create one:
HTML Structure: Create the HTML structure for the menu. This
typically involves using <nav> or <div> elements for the menu
container, and <ul> and <li> elements for the menu items.
CSS Styling: Use CSS to style the menu and make it float on the
page. You can use position: fixed to fix the menu in place and top,
bottom, left, or right properties to position it relative to the viewport.
JavaScript (Optional): You can enhance the functionality of the
floating menu with JavaScript. For example, you can add smooth
scrolling to anchor links within the menu, or you can add animations
to make the menu appear or disappear dynamically.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Floating Menu Example</title>
<style>
Page 13 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
.floating-menu {
position: fixed;
top: 0;
left: 0;
background-color: #333;
padding: 10px;
width: 100%;
z-index: 1000; /* Ensure it's above other content */
}
.menu-item {
display: inline-block;
margin-right: 10px;
color: #fff;
text-decoration: none;
}
</style>
</head>
<body>
<nav class="floating-menu">
<ul>
<li class="menu-item"><a href="#section1">Section 1</a></li>
<li class="menu-item"><a href="#section2">Section 2</a></li>
<!-- Add more menu items as needed -->
</ul>
</nav>
<section id="section1">
<h2>Section 1</h2>
<p>This is the content of section 1.</p>
</section>
<section id="section2">
<h2>Section 2</h2>
<p>This is the content of section 2.</p>
Page 14 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
</section>
</body>
</html>
<label for="city">City:</label>
<select id="city" disabled>
<option value="">Select a city</option>
</select>
<script>
Page 15 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
constcitySelect = document.getElementById('city');
countrySelect.addEventListener('change', function() {
constselectedCountry = this.value;
if (selectedCountry) {
citySelect.innerHTML = '';
const cities = citiesByCountry[selectedCountry];
if (cities) {
citySelect.disabled = false;
citySelect.innerHTML += '<option value="">Select a city</option>';
cities.forEach(city => {
citySelect.innerHTML += `<option
value="${city}">${city}</option>`;
});
} else {
citySelect.disabled = true;
}
} else {
citySelect.disabled = true;
citySelect.innerHTML = '<option value="">Select a city</option>';
}
});
</script>
</body>
</html>
c) Explain how to use banners for displaying advertisement. 4M
Ans. Following are the steps to insert banner advertisement in webpage.
Page 16 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 17 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
<html>
<head>
<script type="text/javascript">
window.status='Welcome to Home Page';
</script>
</head>
<body>
<h1>Hello welcome to JavaScript</h1>
</body>
</html>
5. Attempt any TWO of the following: 12
a) Write HTML script that displays textboxes for accepting 6M
username and password. Write proper JavaScript such that
when the user clicks on submit button
Page 18 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
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. Note: Any other relevant logic shall be considered Create
textboxes
<html> 2M
<head>
<script> Disable
textboxes with
function disableTxt() red color
{ 2M
document.getElementById("un").disabled = true;
Password
document.getElementById('un').style.color = "red"; validation
2M
document.getElementById('aaa').style.color = "red";
document.getElementById("pass").disabled = true;
document.getElementById('pass').style.color = "red";
document.getElementById('bbb').style.color = "red";
}
function validateform(){
var username=document.myform.username.value;
var password=document.myform.password.value;
if (username==null || username==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
</head>
<body>
<form name="myform" method="post" action="" onsubmit="return
validateform()" >
<label id = "aaa">Username:</label>
Page 19 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
+d.toGMTString();
}}
function readCookie()
{
if(document.cookie=="")
document.write("cookies not found");
else
document.write(document.cookie);
}
</script>
</head>
Page 20 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
<body>
<form name="myform" action="">
Enter your name:
<input type="text" name="student"><br>
Enter your Roll No:
<input type="roll no" name="student"><br>
<input type="Reset" value="Set C" type="button"
onclick="writeCookie()">
<input type="Reset" value="Get C" type="button"
onclick="readCookie()">
</form></body>
</html>
c) Write a JavaScript to create rollover effect that involves text and 6M
images. When the user places his or her mouse pointer over a
book title, the corresponding book images appears
Ans. Note: Any other relevant logic shall be considered Correct logic
3M
<html>
<head>
<title> Correct syntax
3M
rollovers</title>
</head>
<body>
<table border="1" width="100%">
<tbody>
<tr valign="top">
<td width="50%">
<a><img height="500" src="motivation.png" width="900"
name="clr"></a></td>
<td><a onmouseover="document.clr.src='blue.png' ">
<b><u>Motivational book</u></b></a>
<br>
<a onmouseover="document.clr.src=education.png' ">
<b><u>Educational book</u></b></a>
<br>
</td>
Page 21 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
</tr>
</tbody>
</table>
</body>
</html>
6. Attempt any TWO of the following: 12
a) Explain following form control / elements with example Button, 6M
Text, TextArea, Select, Checkbox, Form.
Ans. Note: Combined example including all controls / elements shall be Explanation
considered. of each
control with
Button is created by using following code: example 1M
<form method = ―GET‖ action = ―‖><input type = ―button‖ name =
―MyButton‖ value = ―Click‖ onclick = ―msg()‖><form>
There are several types of button, which are specified by the type
attribute:
1. Button which corresponds to the graphic component.
2. Submit, which is associated to the form and which starts the
loading of the file assigned to the action attribute.
3. Image button in which an image loaded from a file.
A Button object also represents an HTML <button> element which
is specified as follows:
<button name = ―btn‖ value = ―MyButton‖ onclick = ―msg()‖>
Example:
<html>
<body>
<h2>Show a Push Button</h2>
<p>The button below activates a JavaScript when it is clicked. </p>
<form>
<input type="button" value="Click me" onclick="msg()">
</form>
<script>
function msg()
{
alert("Hello world!");
}
</script>
Page 22 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
</body>
</html>
Text:
Input ―text‖ is an object to enter a single line of text whose content
will be part of form data.
In html a text is created by following code:
<input type=‖text‖ name=‖textname‖ id=‖textid‖ value=‖
assign_value‖ />
Example:
<script type="text/javascript">
function changeText()
{
var userInput = document.getElementById('userInput').value;
document.getElementById('vp').innerHTML = userInput;
}
</script>
<input type='text' id='userInput' value='Enter Text Here' />
<p>Welcome <b id='vp'>JavaScript</b></p>
<input type='button' onclick='changeText()' value='Change Text'/>
</script>
TextArea:
The Textarea object represents an HTML <textarea> element.
The <textarea> tag indicates a form field where the user can enter a
large amount of text.
You can access a <textarea> element by using getElementById()
Example:
<html>
<body>
<textarea cols="30" rows="5" wrap="hard" readonly="yes"
disabled="yes">
As you can see many times word wrapping is often the desired look
for your textareas. Since it makes everything nice and easy to read
and preserves line breaks.
Page 23 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
</textarea>
</body>
</html>
Checkbox:
<input> elements of type checkbox are rendered by default as boxes
that are checked (ticked) when activated. A checkbox allows you to
select single values for submission in a form (or not).
Syntax for creating checkbox is:
<input type="checkbox" id="myCheck" onclick="myFunction()">
A checkbox can have only two states:
1. Checked
2. Unchecked
Example:
<html>
<body>
<div>
<br>
<input type="checkbox" name="program" id="it" value="IT">
<label for="it">Information Tech</label><br>
<input type="checkbox" name="program" id="co" value="CO"
checked>
<label for="co">Computer Engg</label><br>
<input type="checkbox" name="program" id="ej" value="EJ">
<label for="ej">Electronics</label><br>
<button onclick="validate();">Validate</button>
</div>
<div id="status">
</div>
<script>
function validate()
{
var elements = document.getElementsByName("program");
var statusText = " ";
Page 24 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Select:
Form SELECT elements (<select>) within your form can be
accessed and manipulated in JavaScript via the corresponding Select
object.
To access a SELECT element in JavaScript, use the syntax:
document.myform.selectname //where myform and selectname are
names of your form/element.
document.myform.elements[i] //where i is the position of the select
element within form
document.getElementById("selectid") //where "selectid" is the ID of
the SELECT element on the page.
Example:
<html>
<body>
<select id="programs" size="5">
<option>Computer Engineering</option>
<option>Information Technology</option>
<option>Chemical Engineering</option>
<option>Electronics &TeleComm.</option>
</select>
<p>Click the button to disable the third option (index 2) in the
dropdown list.</p>
<button onclick="myFunction()">Disable Option</button>
<script>
Page 25 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
function myFunction()
{
var x = document.getElementById("programs").options[2].disabled
= true;
document.getElementById("programs").options[2].style.color =
"red";
}
</script>
</body>
</html>
Form:
A form is a section of an HTML document that contains elements
such as radio buttons, text boxes and option lists. HTML form
elements are also known as controls.
Elements are used as an efficient way for a user to enter information
into a form. Typical form control objects also called ―widgets‖
includes the following:
Text box for entering a line of text.
Push button for selecting an action.
Radio buttons for making one selection among a group of
options.
Check boxes for selecting or deselecting a single, independent
option.
The <form> element can contain one or more of the following form
elements:
· <input> · <textarea> · <button> · <select> · <option> · <fieldset> ·
<label>
· <legend>
Syntax:
<form name = ―myform‖ id = ―myform‖ action = ―page.html‖
onSubmit = ―test()‖> -----objects---- </form>
Page 26 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 27 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 28 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Next, you need to define empty functions for each function that you
define in the external JavaScript file.
webpage.html
<html>
<head>
<script src="mycode.js" languages="javascript" type = "text /
javascript">
</script>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
</html>
mycode.js
window.onload=function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
}
c) Develop a JavaScript to create rotating Banner Ads with URL 6M
links.
Ans. Note: Any other correct logic / program shall be considered
<html>
<head>
Correct
<title>Link Banner Ads</title> program 6M
<script language="Javascript" type="text/javascript">
Banners = new Array('1.jpg','2.jpg')
BannerLink = new Array('google.com/', 'msbte.org.in/');
CurrentBanner = 0;
NumOfBanners = Banners.length;
function LinkBanner()
{
document.location.href ="http://www." +
Page 29 / 30
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
BannerLink[CurrentBanner];
}
function DisplayBanners() {
if (document.images) {
CurrentBanner++
if (CurrentBanner == NumOfBanners) {
CurrentBanner = 0
}
document.RotateBanner.src= Banners[CurrentBanner]
setTimeout("DisplayBanners()",1000)
}}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<a href="javascript: LinkBanner()"><imgsrc="1.jpg"
width="400" height="75" name="RotateBanner" /></a>
</center>
</body></html>
Page 30 / 30
Scheme – I
Question Paper Profile
Program Name : Diploma in Engineeering Group
Program Code : CO / CM / CW / IF
Semester
Course Title
: Fifth
: Clint Side Scripting Language (Elective)
22519
Marks : 70 Time: 3 Hrs.
Instructions:
(1) All questions are compulsory.
(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data if necessary.
(5) Preferably, write the answers in sequential order.
b) Write a JavaScript program which compute, the average marks of the following
students Then, this average is used to determine the corresponding grade.
1
The grades are computed as follows :
Range Grade
<60 F
<70 D
<80 C
<90 B
<100 A
c) Write a JavaScript that displays all properties of window object. Explain the code .
d) Write a JavaScript function that checks whether a passed string is palindrome or not.
2
ii) Constructs the mailID as <name>.<surname>@msbte.com and displays mail
ID as message. (Ex. If user enters Rajni as name and Pathak as surname
mailID will be constructed as rajni.pathak@msbte.com) .
b) Write a webpage that diplays a form that contains an input for Username and
password. User is prompted to enter the input and password and password becomes
value of the cookie. Write The JavaScript function for storing the cookie . It gets
executed when the password changes.
c) Write a script for creating following frame structure :
FRAME1
FRAME2 FRAME3
FRUITS
FLOWERS
CITIES
Fruits, Flowers and Cities are links to the webpage fruits.html, flowers.html,
cities.html respectively. When these links are clicked corresponding data appears in
“FRAME3”.
3
Scheme – I
Sample Test Paper - I
Program Name : Diploma in Engineeering Group
Program Code : CO / CM / CW / IF
Semester
Course Title
: Fifth
: Clint Side Scripting Language (Elective)
22519
Marks : 20 Time: 1 Hour
Instructions:
(1) All questions are compulsory.
(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data if necessary.
(5) Preferably, write the answers in sequential order.
4
Scheme – I
Sample Test Paper - II
Program Name : Diploma in Engineeering Group
Program Code : CO / CM / CW / IF
Semester
Course Title
: Fifth
: Clint Side Scripting Language (Elective)
22519
Marks : 20 Time: 1 Hour
Instructions:
(1) All questions are compulsory.
(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data if necessary.
(5) Preferably, write the answers in sequential order.
FRAME2
FRAME3
5
Scheme – I
Question Paper Profile
Program Name : Diploma in Engineeering Group
Program Code :CO/CM/CW/IF
Semester : Fifth
22519
Course Title : Clint Side Scripting Language (Elective)
Marks : 70 Time: 3 Hrs.
Instructions:
(1) All questions are compulsory.
(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data if necessary.
(5) Preferably, write the answers in sequential order.
f) Enlist and explain the use of any two Intrinsic JavaScript functions.
1. getDate() :- This method returns the day of the month for the specified date
according to local time.
syntax: object.getDate();
o Syntax: var retVal = prompt("Enter your name : ", "your name here");
here,
The Object.getOwnPropertyNames() method returns an array of all properties found in
the given object
We have passed window as an object, hence it returns the properties of window object.
a for loop is used to loop through all the properties of window object and display them
var orignalStr;
str=prompt(Ënter a string");
str = str.toLowerCase(); //convert string into
lowercase orignalStr = str;
str = str.split(''); //split the entered string
str = str.reverse(); //reverse the order
str = str.join(''); //then join the reverse order array
values var reverseStr = str;
if(orignalStr == reverseStr)
{
alert("Palindrome"); // return "Palindrome" if true
}
else
{
alert ("Not Palindrome");
}
</script>
</body>
</html>
Q.3) Attempt any THREE of the following. 12 Marks
c) Write a JavaScript that find and displays number of duplicate values in an array.
<html>
<head><title></title></head>
<body>
<script type="text/javascript"> var a =
[10,20,30,10,20,50,60];
document.write("Duplicate Values in array
are");
varnum=0;
for(var i = 0; i <= a.length; i++)
{
for(var j = i; j <= a.length; j++)
{
if(i != j && a[i] == a[j])
{
document.write("<br>"+ a[i]);
num++;
}
}
}
document.write("<br> Number of duplicates : " +
num); </script>
</body>
</html>
d) Write a function that prompts the user for a color and uses what they select to
set the background color of the new webpage opened .
<html>
<head>
<title>
</title>
</head>
<body>
<script type="text/javascript">
var value=confirm("Do u want to change the Backgroud colour");
if(value==true)
{
var name=prompt("Enter which colour do u want:");
document.bgColor=name
}
else
{
alert("you are all set!");
document.write(name);
}
</script>
</body>
</html>
Q.4) Attempt any THREE of the following. 12 Marks
a) State what is a regular expression? Explain its meaning with the help of a
suitable example.
- A regular expression is a sequence of characters that forms a search pattern.
- When you search for data in a text, you can use this search pattern to describe
what you are searching for.
- A regular expression can be a single character, or a more complicated pattern.
- Regular expressions can be used to perform all types of text search and text
replace operation
- Syntax : var pattern = new RegExp(pattern, attributes); or
var pattern = /pattern/attributes;
Where pattern − A string that specifies the pattern of the regular expression or
another regular expression.
Attributes − An optional string containing any of the"g", "i", and "m" attributes
that specify global,case-insensitive, and multi-line matches, respectively.
- Example:regexp = /^[A-Z]/;
- The above example checks whether a string starts with an uppercase letter or not
b) Write a webpage that accepts Username and adharcard as input texts. When
the user enters adhaarcard number ,the JavaScript validates card number and
diplays whether card number is valid or not. (Assume valid adhaar card format
to be nnnn.nnnn.nnnn or nnnn-nnnn-nnnn).
//Program to validate adharcard <body>
<html> <form id="form1">
<head><title>Adhar Card Enter username : <input type="text"
Validation</title> id="user">
<script type="text/javascript"> Enter adharcard no :
function validation(adhar) <input type="text" id="adhar"
{ onblur=validation(document.getEleme
var str = adhar.split("."); ntById("adhar").value)>
if(str.length!=3) </form>
{ </body>
alert("Invalid adharcard number"); </html>
}
else if(str[0].length!=4 ||
str[1].length!=4 ||str[2].length!=4)
{
alert("Invalid adharcard number");
}
else
{
alert("Valid adharcard number");
}
}
</script>
</head>
c) Write the syntax of and explain use of following methods of JavaScript Timing Event.
a. setTimeout()
b. setInterval()
a.setTimeout()
The setTimeout() method calls a function or evaluates an expression after a specified
number of milliseconds.
Syntax :setTimeout(function, milliseconds, param1, param2, ...)
Here, function : The function that will be executed
milliseconds :The number of milliseconds to wait before executing the code.
If omitted, the value 0 is used
param1, param2, ...: Additional parameters to pass to the function
Example: myVar = setTimeout(alertFunc, 3000);
b. setInterval()
This method calls a function or evaluates an expression at specified intervals (in
milliseconds).
The setInterval() method will continue calling the function until clearInterval() is
called, or the window is closed.The ID value returned by setInterval() is used as the
parameter for the clearInterval() method
Syntax:setInterval(function, milliseconds, param1, param2, ...)
Here, function : The function that will be executed
milliseconds :The intervals (in milliseconds) on how often to execute the
code. If the value is less than 10, the value 10 is used
param1, param2, ...: Additional parameters to pass to the function
Example : myVar = setInterval(alertFunc, 3000);
d) Develop JavaScript to convert the given character to Unicode and vice versa.
If the string consists of only one character, use the 0 argument to get the code for that
one character:
var oneChar = myString.substring(12, 13);
var code = oneChar.charCodeAt(0);
e) List ways of Protecting your webpage and describe any one of them.
There are 2 ways of protecting webpage:
1. Disabling right click: The source code of a web page can be viewed by clicking right
mouse button on the webpage. Anyone can see the source code of a webpage which is
not safe. We can hide the code by disabling right mouse click on webpage. Hiding source
code is nothing but protecting the source code by viewing other users.
JavaScript for Disabling right click
<script>
document.addEventListener('contextmenu',event=>event.preventDefault())
</script>
2. Concealing email address:It means hiding email address from unauthorized user. It is
possible with the use of JavaScript.
JavaScript for concealing email address
function (user_email)
{
varavg, splitted, part1, part2;
splitted = user_email.split("@");
part1 = splitted[0];
avg = part1.length / 2;
part1 = part1.substring(0, (part1.length - avg));
part2 = splitted[1];
alert(part1 + "...@" + part2);
};
a) Write HTML Script that displays textboxes for accepting Name, middlename,
Surname of the user and a Submit button. Write proper JavaScript such that
when the user clicks on submit button
i) all texboxes must get disabled and change the color to “RED”. and with
respective labels.
Fruits, Flowers and Cities are links to the webpage fruits.html, flowers.html,
cities.html respectively. When these links are clicked corresponding data appears in
“FRAME3”.
//Frame1.html //Frame3.html
<html> <html>
<head> <head>
<title>Frame1</title> <title>Frame3</title>
</head> </head>
<body> <body>
<h1><center>Frame1</center></h1> <h1><center>Frame3</center></h1>
</body> </body>
</html> </html>
//Frame 2.html //Main Page.html
<html> <html>
<head> <head></head>
<title>Frame2</title> <frameset rows="20%,*">
</head> <frame
<body> src="frame1.html"></frame>
<h1><center>Frame2</center></h1> <frameset cols="50%,*">
<ul> <frame
<li><a href="fruits.html" src="frame2.html"></frame>
target="frame3">fruits</a></li> <frame
<li><a href="flowers.html" src="frame3.html" name="frame3">
target="frame3">flowers</a></li> </frameset>
<li><a href="cities.html" </frameset>
target="frame3">cities</a></li> </html>
</ul>
</body>
</html>
//Fruits.html //Flowers.html //Cities.html
<html> <html> <html>
<script> <script> <script>
document.write("I am document.write("I am document.write("I am
fruits.html"); flowers.html"); cities.html");
</script> </script> </script>
<body> <body> <body>
</body> </body> </body>
</html> </html> </html>
</form>
<script type="text/javascript">
function display()
{
var a=document.getElementById("sel1");
var index = a.selectedIndex;
if(index==0)
{
myform.ta1.value = "New Delhi city and national capital
territory, north-central India. The city of Delhi actually consists of two components:
Old Delhi, in the north, the historic city; and New Delhi, in the south, since 1947 the
capital of India, built in the first part of the 20th century as the capital of British
India. "
}
else if(index==1)
{
myform.ta1.value="Mumbai also known as Bombay is the
capital of the Indian state of Maharashtra. It is the most populous city in India, and
the fourth most populous city in the world, with a total metropolitan area population
of approximately 20.5 million."
}
else
{
"Bangalore is located in the state of Karnataka about 920 meters
above mean sea level on the Deccan Plateau of South India. It covers an area of 741
sq. km. Bangalore, officially called as Bengaluru, is one of the three (other two Delhi
and Mumbai) finest metropolitans in India."
}
}
</script>
</body>
</html>
b) Develop a JavaScript Program to Create Rotating Banner Ads with URL Links.
<html>
<head>
<script language="Javascript">
MyBanners=new Array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg')
MyBannerLinks=new
Array('http://www.amazon.in/','http://www.flipkart.in/','http://aliexpress.in/','http://olx.in/')
banner=0
function ShowLinks()
{
document.location.href=MyBannerLinks[banner]
}
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0
}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<a href="javascript: ShowLinks()">
<imgsrc="banner1.jpg" width="900" height="120" name="ChangeBanner"/></a>
</center>
</body>
</html>
c) Create a slideshow with the group of four images, also simulate the next and
previous transition between slides in your JavaScript.
<html> function changeImage(imgno){ </head>
<head> i = i+imgno <body>
<script> if(i>images.length-1) <imgsrc="image1.jpg" name="slide"
vari=0; { width="400" height="200"><br><br>
var images= new i=0; <input type="button" value="prev"
Array(); } onclick="changeImage(-1)">
var time=3000; if(i<0) <input type="button" value="next"
images[0]="image1.jpg" { onclick="changeImage(1)">
images[1]="image2.jpg" i=images.length-1; </body>
images[2]="image3.jpg" } </html>
document.slide.src=images[i]
} </script>
SANDIP FOUNDATIONS
SANDIP POLYTECHNIC, NASHIK
Academic Year(2023-24)
Question bank for Unit Test – I
• Null: This value can be assigned by reserved word ‘null’. It means no value.
For Example : var i=null;
• Object: It is the entity that represents some value. Ex: Form is an object on which some
components can be placed and used.
For Example : var person = { firstname:"John", lastname:"Doe"};
Property:
• It is the value associated with each object.
• Each object has its own set of properties.
• For example, a form object has a title, a width, and a height—to mention a few properties
Method:
• A method is a process performed by an object when it receives a message.
• For example, a Submit button on a form is an object. Its Submit label and the dimensions of the
button are properties of the button object.
• If you click the Submit button, the form is submitted to the server-side application. In other
words, clicking the Submit button causes the button to process a method.
Main Event:
• Event causes JavaScript to execute the code.
• In JavaScript when user submits form, clicks button, writes something to text box the
corresponding event gets triggered and execution of appropriate code is done through Event
Handling.
6. Write a JavaScript to create person object with properties firstname, lastname, age, eye color,
delete eye color property and display remaining properties of person object.
<html>
<body>
<script>
var person = {
firstname:"John",
lastname:"Doe",
age:50,
eyecolor:"blue"
};
delete person.eyecolor; //delete person eyecolor
document.write("After delete "+ person.firstname +" "+
person.lastname+" "
+person.age +" "+ person.eyecolor);
</script>
</body>
</html>
switch(operator) {
case '+':
result = number1 + number2;
console.log(`${number1} + ${number2} = ${result}`);
break;
case '-':
result = number1 - number2;
console.log(`${number1} - ${number2} = ${result}`);
break;
case '*':
result = number1 * number2;
console.log(`${number1} * ${number2} = ${result}`);
break;
case '/':
result = number1 / number2;
console.log(`${number1} / ${number2} = ${result}`);
break;
default:
console.log('Invalid operator');
break;
}
</script>
</body>
</html>
Chapter – II
10. Write a JavaScript that initialize an array called flowers with the names of 3 flowers. The script
then display array elements.
<html>
<head>
<title>Display Array Elements</title>
</head>
<body>
<script>
var flowers = new Array();
flowers[0] = 'Rose ';
flowers[1] = 'Mogra';
flowers[2] = 'Hibiscus';
for (var i = 0; i < flowers.length; i++)
{
document.write(flowers[i] + '<br>');
}
</script>
</body>
</html>
13. Write a program to Accept the marks of 10 subjects from the user and store it in array. Sort them
and display
<html>
<body>
<h2>Accept and Display the marks</h2>
<script>
a = new Array();
length=prompt("For how many subjects do you want to enter a
marks?");
alert("Enter Marks of Subjects")
for(i=0;i<length;i++)
{
a[i]=prompt("Enter marks of subject"+i);
}
document.write("<br/><br/>The entered subjects marks are<br\>");
for(i=0;i<length;i++)
{
document.write("Marks of subject"+i+"is :"+a[i]);
document.write("</br>");
}
document.write("<br/><br/>The array sorted subjects mareks
are<br\>");
a.sort();
document.write("<br/>The element in the array are<br\>");
for(i=0;i<length;i++)
{
document.write("Marks of subject"+i+"is :"+a[i]);
document.write("</br>"); }
</script>
</body>
Chapter – III
17. explain following form events
i) onmouseup ii) onblur
18. Enlist & Explain the use of any two intrinsic JavaScript functions.
• They are the in built functions which can be used with JavaScript objects
• Various objects supported by JavaScript include document, window, Date , Math , Array, String etc.
• The javascript provides the intrinsic functions for submit or reset button. One can use these
functionalities while submitting the form or resetting the form fields.
• The submit() method of the form object can be used to send the form to the server in exactly same
way as id the user has pressed the submit button.
<html>
<body>
<form name="myform">
Roll No:<input type="text" name="roll"/>
<br/><br/>
Name :<input type="text" name="name"/>
<br/><br/>
<im src="submit.gif"
onclick="javascript.document.forms.myform.submit()"/>
<br/><br/>
</form>
</body>
</html>
4 Marks Questions
Chapter – I
21. Write a JavaScript program which computes average marks of the student and according to
average marks determine the grade
<html>
<head>
<title>Compute the average marks and grade</title>
</head>
<body>
<script>
var students = [['Summit', 80], ['Kalpesh', 77], ['Amit', 88],
['Tejas', 93],['Abhishek', 65]];
var Avgmarks = 0;
for (var i=0; i < students.length; i++)
{
Avgmarks += students[i][1];
}
var avg = (Avgmarks/students.length);
document.write("Average grade: " + (Avgmarks)/students.length);
document.write("<br>");
if (avg < 60)
{
document.write("Grade : E");
}
else if (avg < 70)
{
document.write("Grade : D");
}
else if (avg < 80)
{
document.write("Grade : C");
}
else if (avg < 90)
{
document.write("Grade : B");
}
else if (avg < 100)
{
document.write("Grade : A");
}
</script>
</body>
</html>
for...in loop:
o for...in loop is used to iterate over the properties of an object in JavaScript.
o The for...in loop allows you to access each property of an object. It iterates over the
enumerable properties of an object, and for each property, the loop assigns the property
name to the specified variable.
// An object with some properties
var person = {"name": "Clark", "surname": "Kent", "age": "36"};
Difference :
a. First, the for...in can loop through both Arrays and Objects while the for...of can only loop
through Arrays, Map, Set, arguments object.
b. The second and the biggest difference between both of these statements are, by default,
the for...in iterates over property names and the for...of iterates over property values.
23. Write a JavaScript function that accepts string as a paramenter and find the length of the string.
<html>
<body>
<script type="text/javascript">
var str="HelloWorld";
document.write("The given string is:"+str);
document.write("<br>TheLength of given string is:"+str.length);
</script>
</body>
</html>
24. Explain getter and setter properties in JavaScript
<html>
<head>
<title>Functions</title>
<body>
<script language="Javascript">
var myCar =
{
/* Data properties */
defColor: "blue",
defMake: "Toyota",
/* Accessor properties (getters) */
get color()
{
return this.defColor;
},
get make()
{
return this.defMake;
},
/* Accessor properties (setters) */
set color(newColor)
{
this.defColor = newColor;
},
set make(newMake)
{
this.defMake = newMake;
}
};
document.write("Car color:" + myCar.color + " Car Make:
"+myCar.make)
/* Calling the setter accessor properties */
myCar.color = "red";
myCar.make = "Audi";
/* Checking the new values with the getter accessor properties */
document.write("<p>Car color:" + myCar.color); // red
document.write(" Car Make: "+myCar.make); //Audi
</script>
</head>
</body>
</html>
Chapter – II
25. Write the use of charAt() method and indexOf() method with syntax and example.
charAt()
• The charAt() method requires one argument i.e is the index of the character thatyou want
to copy.
Syntax:
var SingleCharacter = NameOfStringObject.charAt(index);
Example:
var FirstName = 'Bob';
var Character = FirstName.charAt(0); //o/p B
indexOf()
• The indexOf() method returns the index of the character passed to it as an
argument. If the character is not in the string, this method returns –1.
Syntax:
var indexValue = string.indexOf('character');
Example:
var FirstName = 'Bob';
var IndexValue = FirstName.indexOf('o'); //o/p index as 1
26. Difference between concat() and join() method of array with example.
concat() join()
Array elements can be combined byusing Array elements can be combined byusing join()
concat() method of Array object. method of Array object.
The concat() method separates eachvalue The join() method also uses a commato
with a comma. separate values, but you can specify a character
other than a comma to separate values.
Eg: Eg:
var str = cars.concat() var str = cars.join(' ')
The value of str is The value of str in this case is
'BMW, Audi, Maruti' 'BMW Audi Maruti'
27. Write a JavaScript code to display 5 elements of array in sorted order.
<html>
<body>
<h2>Sorting an Array element</h2>
<script>
a = new Array();
a[0]=10;
a[1]=50;
a[2]=40;
a[3]=20;
a[4]=30;
document.write("The elemnts in the array are<br/>")
for(i=0;i<a.length;i++)
{
document.write(a[i]+" ");
}
document.write("<br/><br/>The array is sorted<br\>");
a.sort();
document.write("<br/>The element in the array are<br\>");
for(i=0;i<a.length;i++)
{
document.write(a[i]+" ");
}
</script>
</body>
</html>
28. Write a JavaScript that will replace following specified value with another value in the string
String=”I will fail” replace “fail” by “pass”.
<html>
<head>
<body>
<script>
var myStr = ‘I will fail’;
var newStr = myStr.replace(fail, "pass");
document.write(newStr);
</script>
</body>
</head>
</html>
30. Develop JavaScript to convert the given character to Unicode and vice-versa
• JavaScript String charAt() Method
• The JavaScript string charAt() method is used to find out a char value present at the specified index
in a string.
• The index number starts from 0 and goes to n-1, where n is the length of the string. The index value
can't be a negative, greater than or equal to the length of the string.
• Syntax
• The charAt() method is represented by the following syntax:
String.charAt(index)
Example1
<html>
<body>
<title>JavaScript String charAt() Method</title>
<script>
var str="Sandip Polytechnic";
document.writeln(str.charAt(4));
</script>
</body>
</html>
31. write a javascript function to generate fibonacci series till user defined limit
<html>
<head>
<title> Fibonacci Series in JavaScript </title>
</head>
<body>
<script>
// declaration of the variables
var n1 = 0, n2 = 1, next_num, i;
var num = parseInt (prompt (" Enter the limit for Fibonacci Series "));
document.write( "Fibonacci Series: ");
for ( i = 1; i <= num; i++)
{ document.write (" <br> " + n1); // print the n1
next_num = n1 + n2; // sum of n1 and n2 into the next_num
</script>
</body>
</html>
32. Write a JavaScript program that will remove the duplicate element from an array.
<html>
<head>
<script>
function getUnique(arr){
var uniqueArr = [];
// loop through array
for(let i of arr) {
if(uniqueArr.indexOf(i) === -1) {
uniqueArr.push(i);
}
}
document.write(uniqueArr);
}
var array = [1, 2, 3, 2, 3];
// calling the function
// passing array argument
getUnique(array);
</script>
</head>
<body></body>
</html>
33. Write and explain a string functions for converting string to number and number to string
Using the String() function
• This method accepts an integer or floating-point number as a parameter and converts it into
string type.
Syntax:
String(object);
• Using the parseInt() method: JavaScript parseInt() Method is used to accept the string and
radix parameter and convert it into an integer.
Syntax:
parseInt(Value, radix)
Chapter – III
34. Explain prompt and confirm method of JavaScript with syntax and example
prompt()
• The prompt () method displays a dialog box that prompts the visitor for input.
• The prompt () method returns the input value if the user clicks "OK". If the user clicks "cancel"
the method returns null.
Syntax:
window.prompt (text, defaultText)
Example:
<html>
<script type="text/javascript">
function msg()
{
var v= prompt("Who are you?");
alert("I am "+v);
}
</script>
<input type="button" value="click" onclick="msg()"/>
</html>
confirm()
• It displays the confirm dialog box. It has message with ok and cancel buttons.
• Returns Boolean indicating which button was pressed
Syntax:
window.confirm("sometext");
Example :
<html>
<script type="text/javascript">
function msg()
{
var v= confirm("Are u sure?"); if(v==true){
alert("ok");
}
else{
alert("cancel");
}
}
</script>
<input type="button" value="delete record" onclick="msg()"/>
</html>
35. Write a JavaScript to modify the status bar using onmouseover and 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.
<html>
<head>
<title>JavaScript Status Bar</title></head>
<body>
<a href=" https://msbte.org.in/"
onMouseOver="window.status='MSBTE';return true"
onMouseOut="window.status='';return true">
MSBTE
</a>
</body>
</html>
36. Write a HTML script which displays 2 radio buttons to the users for fruits and vegetables and 1
option list. When user select fruits radio button list should present only fruits to the user & when
user select vegetables radio button option list should present only vegetables names to the user.
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function updateList(ElementValue)
{
with(document.forms.myform)
{
if(ElementValue == 1)
{
optionList[0].text="Mango";
optionList[0].value=1;
optionList[1].text="Banana";
optionList[1].value=2;
optionList[2].text="Apple";
optionList[2].value=3;
}
if(ElementValue == 2)
{
optionList[0].text="Potato";
optionList[0].value=1;
optionList[1].text="Cabbage";
optionList[1].value=2;
optionList[2].text="Onion";
optionList[2].value=3;
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
<p>
<select name="optionList" size="2">
<option value=1>Mango
<option value=2>Banana
<option value=3>Apple
</select>
<br>
<input type="radio" name="grp1" value=1 checked="true"
onclick="updateList(this.value)">Fruits
<input type="radio" name="grp1" value=2
onclick="updateList(this.value)">Vegetables
<br>
<input name="Reset" value="Reset" type="reset">
</p>
</form>
</body>
</html>
37. Describe how to evaluate checkbox selection. Explain with suitable example.
Evaluating Checkbox Selection:
• A checkbox is created by using the input element with the
type=”checkbox” attribute-value pair.
• A checkbox in a form has only two states(checked or un-checked) and is independent of the
state of other checkboxes in the form.
• Check boxes can be grouped together under a common name.
• You can write JavaScript function that evaluates whether or not a check box was selected
and then processes the result according to the needs of your application.
• Following example make use of five checkboxes to provide five options to the user regarding
fruit.
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function selection()
{
var x ="You selected: ";
with(document.forms.myform)
{
if(a.checked == true)
{
x+= a.value+ " ";
}
if(b.checked == true)
{
x+= b.value+ " ";
}
if(o.checked == true)
{
x+= o.value+ " ";
}
if(p.checked == true)
{
x+= p.value+ " ";
}
if(g.checked == true)
{
x+= g.value+ " ";
}
document.write(x);
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Fruits: <br>
<input type="checkbox" name="a" value="Apple">Apple
<input type="checkbox" name="b" value="Banana">Banana
<input type="checkbox" name="o" value="Orange">Orange
<input type="checkbox" name="p" value="Pear">Pear
<input type="checkbox" name="g" value="Grapes">Grapes
<input type="reset" value="Show" onclick="selection()">
</form>
</body>
</html>
</form>
</body>
</html>
SANDIP FOUNDATIONS
SANDIP POLYTECHNIC,NASHIK
Academic Year(2023-24)
Question bank for Unit Test–II
2 Marks Questions
Chapter – IV
1. State any two properties and methods of location object.
Location Object Properties
Property Description
2. Give syntax of and explain the use of “with” statement/clause in JavaScript using suitable example.
The with statement extends the scope chain for a statement.
Syntax
with (expression)
statement
expression:Adds the given expression to the scope chain used when evaluating the
statement. The parentheses around the expression are required.
Statement: Any statement. To execute multiple statements, use a block statement
({ ... }) to group those statements.
Example:
with document
{
write('foo');
body.scrollTop = x;
}
3. Enlist and explain the use of any two Intrinsic JavaScript functions.
•They are the in built functions which can be used with JavaScript objects
•Various objects supported by JavaScript include document, window, Date , Math , Array, String etc.
•The JavaScript provides the intrinsic functions for submit or reset button. One can use these
functionalities while submitting the form or resetting the form fields.
• The submit() method of the form object can be used to send the form to the server in exactly same way
as id the user has pressed the submit button.
1. getDate() :- This method returns the day of the month for the specified date
according to local time.
syntax:object.getDate();
2. max():-This method returns the largest of zero or more numbers.
Syntax:-max(obj1,obj2);
<html>
<body>
<formname="myform">
Roll No:<input type="text" name="roll"/>
<br/><br/>
Name :<input type="text" name="name"/>
<br/><br/>
<imsrc="submit.gif" onclick="javascript.document.forms.myform.submit()"/>
<br/><br/>
</form>
</body>
</html>
b) Permanent cookies
• Permanent cookies, also known as 'persistent cookies', remain in operation even after the web browser
has closed.
• For example, they can remember login details and passwords so web users don't need to re-enter them
every time they use a site.
• The law states that permanent cookies must be deleted after 12 months.
<<html>
<head>
<title>navigator objet</title>
</head>
<body>
<script>
document.writeln("<br/>navigator.appCodeName : " + navigator.appCodeName);
document.writeln("<br/>navigator.appName : " + navigator.appName);
document.writeln("<br/>navigator.appVersion : " + navigator.appVersion);
document.writeln("<br/>navigator.cookieEnabled : " +
navigator.cookieEnabled);
document.writeln("<br/>navigator.language : " + navigator.language);
document.writeln("<br/>navigator.userAgent : " + navigator.userAgent);
document.writeln("<br/>navigator.platform : " + navigator.platform);
document.writeln("<br/>navigator.onLine : " + navigator.onLine);
</script>
</body>
</html>
Chapter – V
9. State the method to put message in web browser status bar?
• The status property of the Window interface was originally intended to set the text in the status bar at
the bottom of the browser window.
<html>
<head>
<script type="text/javascript">
window.status="Welcome to status bar.This is static message";
</script>
</head>
<body>
<h3><p>Building static message in status bar.</p></h3>
</body>
</html>
• In the above program window.status="Welcome to status bar.This is static message"; is a static
message.
• The status property of window object is used to display static message in status bar
10. Construct regular expression for validating the Aadhar Number in following format
only : (nnn)-nnnn-nnnn OR nnn.nnnn.nnnn
• /^\(?([0-9]{3})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;
OR
<html>
<head><title>Validation</title>
<script language="javascript">
function validate()
{
Var adhar = document.myform.adhar.value;
var regex = /^\d{4}\.\d{4}\.\d{4}$|^\d{4}\-\d{4}\-\d{4}$/g
if(!regex.test(adhar))
{
alert("invalid adhar card number");
}
else
{
alert("Valid adhar card number");
}
}
</script>
</head>
<body>
<form name="myform" onSubmit="validate()">
Enter User Name : <input type="text” name=”user"><br><br>
Enter Adhar Card : <input type="text" name="adhar"><br>
<input type="submit">
</form>
</body>
</html>
11. Write a JavaScript to validate zip code (pin code) using regular expression.
(Rules: first 2 digits should start with 40-44)
<!DOCTYPE html>
<html>
<body onload="document.form1.text1.focus()">
<div class="zip">
<form name="form1" action="#">
Enter Zip Code: <input type="text" name="text1" />
<input type="submit" class="validate" name="validate" value="Validate"
onclick="ValidateZip(document.form1.text1)"/>
</form>
</div>
<script>
function ValidateZip(input) {
var validRegex = "^[4]{1}[0-4]{1}[0-9]{4}$";
if (input.value.match(validRegex)) {
alert("Valid Zip Code.");
}
else {
alert("Invalid Zip Code!");
}
}
</script>
</body>
</html>
<html>
<head>
<script type="text/javascript">
Function changecontent()
{
document.write("<h3><p>After clicking the button:new content</p></h3>")
}
</script>
</head>
<body>
<p>Click to change the content of whole window</p>
<input type="button" value="Change Content" onclick="changecontent()"/>
<h3><p id="para">Before Clicking the Button:Old Content</p></h3>
</body>
</html>
13. Write 4 attributes of <frameset> with meaning and example.
i. cols - Specifies how many columns are contained in the frameset and the size of each column.
For example, to create three vertical frames, use cols = "100, 500, 100".
ii. rows - This attribute works just like the cols attribute and takes the same values, but it is used to specify
the rows in the frameset.
For example, to create two horizontal frames, use rows = "10%, 90%".
iii. border - This attribute specifies the width of the border of each frame in pixels.
For example, border = "5". A value of zero means no border.
iv. frameborder - This attribute specifies whether a three-dimensional border should be displayed between
frames. This attribute takes value either 1 (yes) or 0 (no).
For example, frameborder = "0" specifies no border.
<html>
<head>
<script>
function display()
{
parent.frame2222.document.getElementById("para").innerHTML="Element of frame
2 is accessed from frame1";
}
</script>
</head>
<body>
<h4>Frame 1</h4>
<input type="button" name="button1" value="Click" onclick="display()"/>
</body>
</html>
<html>
<body>
<h4>Frame 2</h4>
<p id="para">Frame 2 content</p>
</body>
</html>
Chapter – VI
15. Explain frameworks of JavaScript and its application.
• JS frameworks are JavaScript programming libraries that have pre-written code to use for standard
programming functions and tasks.
• It’s a framework to create websites or web applications around.
• First and foremost, it will increase your productivity. Think of it as a workaround of sorts: you have to
write fewer code manually because there are already pre-written and ready-to-use functions and
patterns.
• Some components of the website do not need to be custom-made, so you can build and expand on pre-
built ones.
• Frameworks are more adaptable for website design and most website developers prefer it. Let’s take a
look at the best JS Frameworks.
a. ReactJs
b. Angular
c. Vue.js
d. jQuery
e. Backbone.js
f. Node.js
g. Ember.js
h. Meteor
i. Polymer
j. Aurelia
16. Write a JavaScript program that create a scrolling text on the status line of a window. We can show a
message scrolling in status bar by assigning the spaces and the message to the status bar in time
interval
<html>
<head>
<title>Scrolling Text</title>
<script language="JavaScript">
Var scrollPos = 0
Var maxScroll = 100
var blanks = ""
Function displayText(text) {
window.defaultStatus = blanks + text
++scrollPos
blanks += " "
if(scrollPos>maxScroll) {
scrollPos = 0
blanks = ""
}
}
</script>
</head>
<body onload="scrollText('Watch this text scroll!!!', 300)">
<p>Watch the text scroll at the bottom of this window!</p>
</body>
</html>
• In the above program window.setInterval("displayText('"+text+"')",milliseconds) is used to set the
scrolling message.
• Thesetinterval() function is used to set the message after milliseconds.
• The text will send to the function displaytext() function, this function is called after milliseconds defined
in setinterval() function.
• After calling the displaytext() function, the statement window.defaultStatus=blank + text is executed.
• In which the status of the window is changed by setting the new text to defaultstatusproperty of
window object
17. Develop a JavaScript Program to Create Rotating Banner Ads with URL Links.
OR
Write a JavaScript program to link banner advertisements to different URLs.
<html>
<head>
<script language="Javascript">
MyBanners=new Array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg')
MyBannerLinks=new Array('http://www.amazon.in/', 'http://www.flipkart.in/',
'http://aliexpress.in/','http://olx.in/')
banner=0
function ShowLinks()
{
document.location.href=MyBanner Links[banner]
}
Function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0
}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<a href="javascript: ShowLinks()">
<imgsrc="banner1.jpg"width="900"height="120"name="ChangeBanner"/></a>
</center>
</body>
</html>
18. List ways of protecting your web page and describe any one of them.
Ways of protecting Web Page:
1. Hiding your source code
2. Disabling the right Mouse Button
3. Hiding JavaScript
4. Concealing E-mail address.
There are 2 ways of protecting webpage:
1. Disabling right click: The source code of a web page can be viewed by clicking rightmouse button on
the webpage. Anyone can see the source code of a webpage which isnot safe. We can hide the code by
disabling right mouse click on webpage. Hiding sourcecode is nothing but protecting the source code
by viewing other users.
JavaScript for Disabling right click
<script>
document.addEventListener('contextmenu',event=>event.preventDefault())
</script>
2. Concealing email address:It means hiding email address from unauthorized user. It ispossible with the
use of JavaScript.
JavaScript for concealing email address
function (user_email)
{
varavg, splitted, part1, part2;
splitted = user_email.split("@");
part1 = splitted[0];
avg = part1.length / 2;
part1 = part1.substring(0, (part1.length - avg));
part2 = splitted[1];
alert(part1 + "...@" + part2);
};
Syntax: event.preventDefault()
Example:
<!DOCTYPE html>
<html>
<body>
<a id="google" href="https://google.com/"> Go to Google </a>
<script>
document.getElementById("google").addEventListener
("click",function(event) {event.preventDefault();});
</script>
</body>
</html>
4 Marks
QuestionsChapter – IV
20. Describe, how to read cookie value and write a cookie value. Explain with example.
OR
Write a JavaScript program to create read, update and delete cookies.
OR
Describe, how to read cookie value and write a cookie value. Explain with example.
• JavaScript can create, read, and delete cookies with the document.cookie property.
• With JavaScript, a cookie can be created like this:
document.cookie = "username=student";
• You can also add an expiry date (in UTC time). By default, the cookie is deleted when the browser is
closed:
document.cookie="username=student;expires=Thu,18 Dec2013 12:00:00 UTC";
• With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie
belongs to the current page.
document.cookie = "username=student; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
Read cookie
You can access the cookie like this which will return all the cookies saved
for the current domain.
var x = document.cookie
Delete cookie
To delete a cookie, you just need to set the value of the cookie to empty and set the
value of expires to a passed date.
document.cookie = "cookiename= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
For example, let's say you want to delete the "user_preferences" cookie that was
created earlier. You could use the following code to do so:
// Create the string representing the cookie, including an expiration date in the past
var userPreferencesCookie = "user_preferences=; expires=Thu, 01 Jan 1970 00:00:00
UTC";
• The open() method returns a reference to the new window, which is assigned to the
MyWindow variable. You then use this reference any time that you want to do something
with the window while your JavaScript runs.
• A window has many properties, such as its width, height, content, and name—to mention a
few. You set these attributes when you create the window by passing them as parameters
to the open() method:
• The first parameter is the full or relative URL of the web page that will appear in the new
window.
• The second parameter is the name that you assign to the window.
• The third parameter is a string that contains the style of the window.
• We want to open a new window that has a height and a width of 250 pixels and displays an
advertisement that is an image. All other styles are turned off.
Syntax:
MyWindow = window.open(‘webpage1.html’, 'myAdWin', 'status=0, toolbar=0,
location=0, menubar=0, directories=0, resizable=0, height=250,
width=250')
Example:
<!DOCTYPE html>
<html>
<body>
Click the button to open new window <br><br>
<button onclick="window.open ('https://www.google.com', 'Google',
'width=520,
height=650, status')"> Open Window </button>
</body>
</html>
22. Write a JavaScript that creates a persistent cookies of Item names. Write appropriate HTML script
for the same.
OR
Explain how to create and read Persistent Cookies in JavaScript with example.
• Permanent cookies
• Permanent cookies, also known as 'persistent cookies', remain in operation even after the web browser
has closed.
• For example, they can remember login details and passwords so web users don't need to re-enter them
every time they use a site. The law states that permanent cookies must be deleted after 12 months.
<html>
<head><title>Persistent Cookie</title>
<script language="javascript">
Function createcookie()
{
var name=form1.nm.value;
var c1 = form1.s1.options[form1.s1.selectedIndex].value
var c2 = form1.s2.options[form1.s2.selectedIndex].value
var d = new Date();
d.setMonth(d.getMonth()+1);
cookievalue="user="+name+",item1="+c1
+",item2="+c2+";expires="+d.toUTCString();
alert("Cookie Created");
}
</script>
</head>
<body>
<form name="form1" onsubmit="createcookie()">
Enter name:<input type="text"name="nm"><br>
Select item-1 <selectname="s1">
<option> CD </option>
<option> DVD </option>
<option> BluRay</option>
<option> Pen drive </option>
</select>
Select item-2 <select name="s2">
<option> C Prog</option>
<option> C++ Prog</option>
<option> Java</option>
<option>DotNet</option>
</select>
<input type="Submit" value="Submit">
</form>
</body>
</html>
23. Write HTML Script that displays textboxes for accepting Name, middle name, Surname of the user
and a Submit button. Write proper JavaScript such that when the user clicks on submit button
a. alltexboxes must get disabled and change the color to “RED”. and with respective labels.
b. Constructs the mailID as <name>.<surname>@msbte.com and displays mail ID as message. (Ex.
If user enters Rajni as name and Pathak as surname mailID will be constructed as
rajni.pathak@msbte.com)
<html>
<head>
<script>
function a()
{
document.getElementById("fname").disabled=true;
document.getElementById("mname").disabled=true;
document.getElementById("sname").disabled=true;
fname.style.backgroundColor = "red";
mname.style.backgroundColor = "red";
sname.style.backgroundColor = "red";
var firstName = fname.value;
var lastName = sname.value;
var email = firstName +"."+ lastName +"@msbte.com";
alert(email);
}
</script>
</head>
<body>
<form id="myform">
Enter First Name: <input type="text" id="fname"><br>
Enter Middle Name: <input type="text" id="mname"><br>
Enter Sur Name: <input type="text" id="sname"><br>
<input type="button" value="Submit" onclick="a()"><br>
</form>
</body>
</html>
24. Write a webpage that displays a form that contains an input for Username and password. User is
prompted to enter the input and password and password becomes value of the cookie. Write The
JavaScript function for storing the cookie . It gets executed when the password changes.
<html>
<head><title>Cookie</title>
<script language="javascript">
function store()
{
var user = document.form1.user.value
var pass = document.form1.pass.value
var cookieinfo = "username="+user+",password="+pass;
document.cookie = cookieinfo
alert(document.cookie + " Stored");
}
</script>
</head>
<body>
<form name="form1" onsubmit="store()">
Enter username <input type="text" name="user">
Enter password <input type="password" name="pass" onchange="store()">
<input type="submit" value="Submit">
</form>
</body>
</html>
25. Write html code to design a form that displays two buttons START and STOP. Write a JavaScript
code such that when user clicks on START button, real time digital clock will be displayed on
screen. when user clicks on STOP button, clock will stop displaying time
<html>
<body>
<div id="MyClockDisplay" class="clock">
</div>
<style>
body {
background: black;
}
.clock {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
color: #17D4FE;
font-size: 60px;
font-family: Orbitron;
letter-spacing: 7px;
}
</style>
<script>
function showTime()
{
var date=new Date();
var h=date.getHours(); // 0 - 23
var m=date.getMinutes(); // 0 - 59
var s=date.getSeconds(); // 0 - 59
var session="AM";
if(h==0)
{
h=12;
}
if(h>12)
{
h=h-12;
session="PM";
}
h=(h<10)?"0"+h:h;
m=(m<10)?"0"+m:m;
s=(s<10)?"0"+s:s;
setTimeout(showTime,1000);
}
function stopTime()
{
var h="00";
var m="00";
var s="00";
var session="AM";
var time=h+":"+m+":"+s+" "+session;
document.getElementById("MyClockDisplay").innerText=time;
document.getElementById("MyClockDisplay").textContent=time;
}
</script>
<input type="button" value="START" onclick="showTime()"/>
<input type="button" value="STOP" onclick="stopTime()"/>
</body>
</html>
Chapter – V
26. State what is regular expression. Explain its meaning with the help of a suitable example.
• A regular expression is a sequence of characters that forms a search pattern.
• When you search for data in a text, you can use this search pattern to describewhat you are searching
for.
• A regular expression can be a single character, or a more complicated pattern.
• Regular expressions can be used to perform all types of text search and textreplace operation
Syntax
/pattern/modifiers;
Example
var patt = /w3schools/I
Example explained:
• /w3schools/i is a regular expression.
• w3schools is a pattern (to be used in a search).
• i is a modifier (modifies the search to be case-insensitive).
Modifiers
Modifiers are used to perform case-insensitive and global searches:
Modifier Description
g Perform a global match (find all matches rather than stopping after the first match)
27. Describe regular expression. Explain search () method used in regular expression with suitable
example.
Regular expression - A regular expression is a sequence of characters that specifies a
search pattern in text.
search () - The search () method searches a string for a specified value and returns the position of the
match. The search value can be string or a regular expression. This method returns -1 if no match is
found.
<html>
<body>
<h1>JavaScript String Methods</h1>
<p>Search a string for "W3Schools", and display the position of the
match:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools!";
let n = text.search("W3Schools");
document.getElementById("demo").innerHTML = n;
</script>
</body>
</html>
28. Explain test() and exec() method of Regular Expression object with example.
The exec() method
The exec() method makes a search for the specified match of the string in the given string. If the match
of the string is present in the given string it returns an array and if the match is not found in the given
string, then it returns a null value.
In other words, The exec() method takes a string as the parameter. This string is which is to be checked
for match in the given string.
Syntax
This is the syntax of the exec() method of regular expressions in JavaScript −
regularExpressionObj.exec(string)
Example
<html>
<body>
<p>click to get exec() method output</p>
<button onclick="findMatch()">Search</button>
<p id="tutorial"></p>
<script>
function findMatch() {
var txt ="Learning regular expressions in JavaScript";
var search1 = new RegExp("JavaScript");
var search2 = new RegExp("Abdul")
var res1 = search1.exec(txt);
var res2 = search2.exec(txt);
document.getElementById("tutorial").innerHTML ="Given string
is:"+txt +"<br>"+ "Specific word to match are:"+search1+"
"+search2+"<br>"+"Result of two search keys: "+res1+" "+res2
}
</script>
</body>
</html>
Syntax
This is the syntax of the test() method in JavaScript −
regularExpressionObj.test(string)
This also takes the given input string as the parameter and returns the Boolean result.
Example
<html>
<body>
<p>click to get exec() method output</p>
<button onclick="findMatch()">Search</button>
<p id="tutorial"></p>
<script>
function findMatch() {
var txt ="Learning regular expressions in JavaScript";
var search1 = new RegExp("JavaScript");
var search2 = new RegExp("Abdul")
var res1 = search1.test(txt);
var res2 = search2.test(txt);
document.getElementById("tutorial").innerHTML ="Given string
is:"+txt+"<br>"+ "Specific word to match are:"+search1+"
"+search2+"<br>"+"Result of two search keys: "+res1+" "+res2
}
</script>
</body>
</html>
29. Write a JavaScript program to validate email ID of the user using regular expression.
<html>
<body onload="document.form1.text1.focus()">
<div class="mail">
<form name="form1" action="#">
Enter your email address: <input type="text" name="text1" />
<input type="submit" class="validate" name="validate" value="Validate"
onclick="ValidateEmail(document.form1.text1)"/>
</form>
</div>
<script>
function ValidateEmail(input) {
var validRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[azA-
Z0-9-]+)*$/;
if (input.value.match(validRegex)) {
alert("Valid email address!");
}
else {
alert("Invalid email address!");
}}
</script>
</body>
</html>
30. Write a JavaScript function to check whether a given value is valid IP value or not
<html>
<head>
<title>IP address validation</title>
<script type='text/javascript'>
function validate( value ) {
const regexExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-
5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
if(regexExp.test(value))
{
alert("It is a valid IP Address");
}
else
{
alert("It is a not valid IP Address");
}}
</script>
</head>
<body>
Address: <input type='text' onchange='validate(this.value)'>
</body>
</html>
Creating Rollover
• To create rollover we use ’onmouseover’ event.
• When the mouse pointer is moved onto an element, onto one of its children, the mouseover element is
occurred.
• The onmouseover event is generally used with the ‘onmouseout’.
• When the mouse pointer is moved out of the element, the onmouseout element is occurred.
<html>
<body>
<p onmouseover="this.style.color='red'"
onmouseout="this.style.color='blue'">
Move the mouse over this text to change its color to red. Move the mouse away
to
change the text color to blue.
</p>
</body>
</html>
32. Write a JavaScript program to create rollover effect for three images.
• You create a rollover for text by using the onmouseover attribute of the <A> tag, which is the anchor
tag.
• You assign the action to the onmouseover attribute the same way as you do with an <IMG> tag.
• Let's start a rollover project that displays a flower titles.
• Additional information about a flower can be displayed when the user rolls the mouse cursor over the
flower name.
• In this example, the image of the flower is displayed. However, you could replace the flower image
with an advertisement or another message that you want to show about the flower.
<html>
<body>
<h1>Image Rollover</h1>
<a><IMG src='apples.gif' height="92" width="70" border="0"
onmouseover=" src='apples.gif'" onmouseout="src='redstar.gif'"></a>
<a><IMG src='ND1.png' height="92" width="70" border="0"
onmouseover="src='ND1.png'" onmouseout="src='M1.png' "></a>
<a><IMG src='M1.png' height="92" width="70" border="0"
onmouseover="src='M1.png' " onmouseout="src='B.png' "></a>
</body>
</body>
</html>
OR
<!DOCTYPE html>
<html>
<body>
<img height="500" src="apple.jpg" width="500" name="clr"> <br>
<a onmouseover="document.clr.src='apple.jpg'"> Apple </a> <br>
<a onmouseover="document.clr.src='mango.jpg'"> Mango </a> <br>
<a onmouseover="document.clr.src='orange.jpg'"> Orange </a>
</body>
</html>
33. Write a JavaScript program to design HTML page with books information in tabular format, use
rollovers to display the discount information.
<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<th> Book </th>
<th> Price </th>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount: 15%'">
<td> CSS </td>
<td> 230 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount: 10%'">
<td> AJP </td>
<td> 240 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount: 12%'">
<td> OSY </td>
<td> 260 </td>
</tr>
</table>
<p id="discount"></p>
</body>
</html>
34. 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
a. Name Validation
b. Email ID Validation.
<html>
<body>
<form action="#" name="myForm" onsubmit="validate()">
Name: <input type="text" name="name" /> <br><br>
Email: <input type="text" name="email" /> <br><br>
<input type = "submit" value = "Submit" />
</form>
<script>
function validate() {
if( document.myForm.name.value == "" ) {
alert("Please provide your name!");
return false;
}
var emailID = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zAZ0-
9-]+)*$/;
if( document.myForm.email.value == "" ) {
alert("Please provide your Email!");
}
else if (document.myForm.email.value.match(emailID)) {
alert("Valid Name and Email.");
}
else{
alert("Please enter valid email ID!");
}
}
</script>
</body>
</html>
FRUITS, FLOWERS AND CITIES are links to the webpage fruits.html,flowers.html, cities.html
respectively. When these links are clicked corresponding data appears in FRAME 3.
OR
Write a script for creating following frame structure:
Frame 1 contains three button SPORT, MUSIC and DANCE that will perform following action:
When user clicks SPORT button, sport.html webpage will appear in Frame 2.
When user clicks MUSIC button, sport.html webpage will appear in Frame 3.
When user clicks DANCE button, sport.html webpage will appear in Frame 4.
<html>
<head>
<title>Frame Demo</title>
</head>
<body>
<table border="1">
<tr>
<td align="center" colspan="2"> FRAME 1
</td>
</tr>
<tr>
<td> FRAME 2
<ul>
<li>
<a href="fruits.html" target="mainframe">FRUITS</a>
</li>
<li>
<a href="flowers.html" target="mainframe">FLOWERS</a>
</li>
<li>
<a href="cities.html" target="mainframe">CITIES</a>
</li>
</ul>
</td>
<td>
FRAME 3<BR>
<iframe name="mainframe"></iframe>
</td>
</tr>
</table>
</body>
</html>
Chapter – VI
36. Create a slideshow with the group of three images, also simulate next and previous transition
between slides in your Java Script.
<html>
<head>
<script>
pics = new Array('1.jpg' , '2.jpg' , '3.jpg'); count = 0;
function slideshow(status)
{
if (document.images)
{
count = count + status;
if (count > (pics.length - 1))
{
count = 0;
}
if (count <0)
{
count = pics.length - 1;
}
documet.imag1.src = pics[count];
}
}
</script>
</head>
<body>
<img src="1.jpg" width="200" name="img1">
<br>
<input type="button" value="Next" onclick="slideshow(1)">
<input type="button" value="Back" onclick="slideshow(-1)">
</body>
</html>
37. Create a slideshow with the group of four images, also simulate the next and previous transition
between slides in your JavaScript.
<html>
<head>
<script>
Var i=0;
var images= new
Array();
var time=3000;
images[0]="image1.jpg"
images[1]="image2.jpg"
images[2]="image3.jpg"
function changeImage(imgno){
i = i+imgno
if(i>images.length-1)
{
i=0;
}
if(i<0)
{
i=images.length-1;
}
document.slide.src=images[i]
}
</script>
</head>
<body>
<imgsrc="image1.jpg" name="slide" width="400" height="200"><br><br>
<input type="button" value="prev" onclick="changeImage(-1)">
<inputtype="button" value="next" onclick="changeImage(1)">
</body>
</html>
38. Write a HTML script which displays 2 radio buttons to the users for fruits and vegetables and 1
option list. When user select fruits radio button option list should present only fruits names to the
user & when user select vegetable radio button option list should present only vegetable names
to the user.
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
functionupdateList(ElementValue)
{
with(document.forms.myform)
{
if(ElementValue == 1)
{
optionList[0].text="Mango"; optionList[0].value=1;
optionList[1].text="Banana"; optionList[1].value=2;
optionList[2].text="Apple"; optionList[2].value=3;
}
if(ElementValue == 2)
{
optionList[0].text="Potato"; optionList[0].value=1;
optionList[1].text="Cabbage"; optionList[1].value=2;
optionList[2].text="Onion"; optionList[2].value=3;
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
<p>
<select name="optionList" size="2">
<option value=1>Mango
<option value=2>Banana
<option value=3>Apple
</select>
<br>
<input type="radio" name="grp1" value=1 checked="true"
onclick="updateList(this.value)"> Fruits
<input type="radio" name="grp1" value=2
onclick="updateList(this.value)"> Vegetables
<br>
<input name="Reset" value="Reset" type="reset">
</p>
</form>
</body>
</html>
39. Write HTML Script that displays dropdownlist containing options NewDelhi, Mumbai, Bangalore.
Write proper JavaScript such that when the user selects any options corresponding description of
about 20 words and image of the city appear in table which appears below on the same page.
<html>
<head>
<title>Drop down list example</title>
</head>
<body>
<pid="p1"></p>
<form name="myform">
<select id="sel1">
<option value="delhi">
NewDelhi
</option>
<option value="Mumbai">
Mumbai
</option>
<option value="bangalore">
Bangalore
</option>
</select>
<br><input type="button" name="bt1" id="b1" onclick="display()"
value="click">
<input type="textarea" name="ta1">
</form>
<script type="text/javascript">
function display()
{
var a=document.getElementById("sel1");
var index = a.selectedIndex;
if(index==0)
{
myform.ta1.value = "New Delhi city and national capital territory, north-
central India. The city of Delhi actually consists of two components: Old
Delhi, in the north, the historic city; and New Delhi, in the south, since
1947 the capitalof India, built in the first part of the 20th century as
the capital of British India. "
}
elseif(index==1)
{
myform.ta1.value="Mumbai also known as Bombay is the capital of the Indian
state of Maharashtra. It is the most populous city in India, and the fourth
most populous city in the world, with a total metropolitan area population
of approximately 20.5 million."
}
else
{
"Bangalore is located in the state of Karnataka about 920 meters above mean
sea level on the Deccan Plateau of South India. It covers an area of741 sq.
km. Bangalore, officially called as Bengaluru, is one of the three (other
two Delhi and Mumbai) finest metropolitans in India."
}
}
</script>
</body>
</html>
40. Write a JavaScript to create option list containing list of images and then display images in new
window as per selection.
<body>
<center>
<h1 style="color: green">
GeeksforGeeks
</h1>
<div class="dropdown">
<button class="dropbtn">
Country Flags
</button>
<div class="dropdown-content">
<a href="#">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200630132503/iflag.jpg"
width="20" height="15"> India</a>
<a href="#">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200630132504/uflag.jpg"
width="20" height="15"> USA</a>
<a href="#">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200630132502/eflag.jpg"
width="20" height="15"> England</a>
<a href="#">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200630132500/bflag.jpg"
width="20" height="15"> Brazil</a>
</div>
</div>
</center>
</body>
</html>
41. Write a JavaScript to create a pull-down menu with four options [AICTE, DTE,MSBTE, GOOGLE].
Once the user will select one of the options then user will be redirected to that site.
OR
Write a JavaScript to create a pull-down menu with three options [Google, MSBTE, Yahoo]
once the user will select one of the options then user will be redirected to that site.
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
Function getPage(choice)
{
page=choice.options[choice.selectedIndex].value;
if(page != "")
{
window.location=page;
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Website:
<select name="MenuChoice"onchange="getPage(this)">
<option value="https://www.google.com">Google</option>
<option value="https://www.msbte.org.in">MSBTE</option>
<option value="https://www.yahoo.com">Yahoo</option>
</form>
</body>
</html>