Important Instructions To Examiners:: Maharashtra State Board of Technical Education (ISO/IEC - 27001 - 2013 Certified)
Important Instructions To Examiners:: Maharashtra State Board of Technical Education (ISO/IEC - 27001 - 2013 Certified)
(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