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

JavaScript IMP Questions by Vishal Sir

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

JavaScript IMP Questions by Vishal Sir

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

CSS/JavaScript Important Questions

Client-Side Scripting (JavaScript)


IMP QUESTIONS LIST

Author:

“Prof. Vishal Jadhav”


(BE in Computer Engineering and Having 8.5 years of IT industry experience + 9 years
of Teaching experience)
VJTech Academy, Maharashtra Contact No: +91-9730087674,
Email id: [email protected])

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 1
CSS/JavaScript Important Questions

1. State the features of JavaScript.


 JavaScript is an object-based scripting language.
 Giving the user more control over the browser.
 It Handling dates and time. 4. It detecting the user's browser and OS.
 It is light weighted. 6. JavaScript is a scripting language and it is not java.
 JavaScript is interpreter-based scripting language.
 JavaScript is case sensitive.
 JavaScript is object-based language as it provides predefined objects.
 Every statement in JavaScript must be terminated with semicolon (;).
 Most of the JavaScript control statements syntax is same as syntax of control
statements in C language.

2. Differentiate between session cookies and persistent cookies

Session Cookies Persistent Cookies


1)Session cookies known as temporary 1) Persistent cookies known as permanent
cookies. cookies.
2) Also known as an in-memory cookie 2) Also known as transient cookie.
3) A session cookie is a cookie that is not 3) A persistent cookie is a cookie that is
assigned an expiration date. assigned an expiration date.
4) It resides in memory for the length of the 4) It is written to the computer’s hard disk and
browser session. remains there until the expiration date has
been reached; then it’s deleted.
5) Session cookie is automatically deleted 5) Persistent cookie is not automatically
when the user exits the browser application. deleted when the user exits the browser
application.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 2
CSS/JavaScript Important Questions

3. Write a JavaScript program to check whether entered number is prime or not.

<html>
<body>
<script language="javascript" type="text/javascript">
var no=prompt("Enter Number:");
var flag=0;
for(i=2;i<no;i++)
{
if(no%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
document.write("Number is Prime");
}
else
{
document.write("Number is not Prime");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 3
CSS/JavaScript Important Questions

4. Explain following form events: (i) onmouseup (ii) onblur


onmouseup:
- The onmouseup event occurs when a mouse button is released over an element.
- onmouseup event is occurs when the user releases the mouse button while the cursor is
positioned on the element.
onblur:
- The onblur event occurs when an element loses focus.
- The onblur event is used on input fields.
- The onblur event is used with form validation

Example:

<html>
<body>
<form name="myform">
<input type="text" name="tf1" id="id1">
<input type="button" name="b1" value="OK" onmouseup="display1()" onblur="display2()">
</form>
<script language="javascript" type="text/javascript">
function display1()
{
document.getElementById("id1").value="onmouseup event occurred";
}
function display2()
{
document.getElementById('id1').value="onblur event occurred";
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 4
CSS/JavaScript Important Questions

5. Write a JavaScript program to changing the contents of a window.

<html>
<body>
<input type="button" name="b1" value="Website1" onclick="OpenWindow('https://www.vjtechacademy.in')">
<input type="button" name="b2" value="Website2" onclick="OpenWindow('https://msbte.org.in/')">

<script language="javascript" type="text/javascript">


function OpenWindow(url)
{
window.open(url,"vjtech","width=500,height=500 top=100 left=100");
}
</script>
</body>
</html>

6. Explain frame works of JavaScript and its application.


- A JavaScript framework is a collection of JavaScript code libraries that provide a web
developer with pre-written code for routine programming tasks. Frameworks are structures
with a particular context and help you create web applications within that context.
- It is completely possible to build strong web applications without JavaScript frameworks, but
frameworks provide a template that handles common programming patterns. Each time you
have to build an application, you don’t need to write code for every single feature from
scratch. Instead, you can build upon an existing feature set.
- JavaScript frameworks, like most other frameworks, provide some rules and guidelines.
Using these rules and guidelines, any developer can make complex applications faster and
more efficiently than if they decided to build from scratch. The rules and guidelines help
shape and organize your website or web application too!

Applications:

a) Web Development JavaScript is a scripting language used to develop web pages.


b) Web Applications Various JavaScript frameworks are used for developing and
building robust web applications.
c) Presentations A very popular application of JavaScript is to create interactive
presentations as websites.
d) Server Applications
e) Web Servers
f) Games

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 5
CSS/JavaScript Important Questions

7. List the comparison operators in Java script.


Comparison operators in Java script
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
=== Equal value and equal type
!== not equal value or not equal type

8. Write a Java script to create person object with properties firstname, lastname, age, eyecolor,
delete eyecolor property and display remaining properties of person object.

<html>
<body>
<script>
var person = {
firstname:"Vishal",
lastname:"Jadhav",
age:29,
eyecolor:"blue"
};
delete person.eyecolor;
document.write("After delete properties of person object: ")
document.write("<br>First Name:"+person.firstname);
document.write("<br>Last Name:"+person.lastname);
document.write("<br>age:"+person.age);
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 6
CSS/JavaScript Important Questions

9. Write a Java script that initializes an array called flowers with the names of 3 flowers. The
script then displays array elements.

<html>
<body>
<script>
var flowers = new Array();
flowers[0] = 'Rose';
flowers[1] = 'Mogra';
flowers[2] = 'Lotus';
for (var i = 0; i < flowers.length; i++)
{
document.write(flowers[i] + '<br>');
}
</script>
</body>
</html>

10. Write Javascript to call function from HTML.

<html>
<body>
<input type="button" name="b1" value="Click Me" onclick="display()">
<script>
function display()
{
document.write("This is user defined function");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 7
CSS/JavaScript Important Questions

11. Write a Javascript to design a form to accept values for user ID & password.

<html>
<body>
<form name="myform">
Enter User ID:<input type="text" id="tf1">
Enter Password:<input type="password" id="tf2">
<input type="button" name="b1" value="Display" onclick="show()">
</form>
<script>
function show()
{
var id=document.getElementById("tf1").value;
var psw=document.getElementById("tf2").value;
document.write("<br>Your User ID:"+id);
document.write("<br>Your Password:"+psw);
}
</script>
</body>
</html>

12. State any two properties and methods of location object.


Properties of location object:
1. hash
2. host
3. hostname
4. href
5. origin

Methods of location object:

1. assign( )

2. reload( )

3. replace( )

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 8
CSS/JavaScript Important Questions

13. Explain getter and setter properties in Java script with suitable example
In JavaScript, there are two kinds of object properties:

 Data properties

 Accessor properties

Accessor Property

In JavaScript, accessor properties are methods that get or set the value of an object. For that,
we use these two keywords:

 get - to define a getter method to get the property value


 set - to define a setter method to set the property value

JavaScript Getter

 To create a getter method, the get keyword is used.

In JavaScript, getter methods are used to access the properties of an object. For example,

<html>
<body>
<script language="javascript" type="text/javascript">
var student={
FirstName:'Brenden',
get getData()
{
return this.FirstName;
}
};
document.write(student.FirstName);
document.write(student.getData);
</script>
</body>
</html>

 In the above program, a getter method getName() is created to access the property of an
object.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 9
CSS/JavaScript Important Questions

JavaScript Setter

 To create a setter method, the set keyword is used.


 In JavaScript, setter methods are used to change the values of an object. For example,

<html>
<body>
<script language="javascript" type="text/javascript">
var student={
FirstName:'Brenden',
set putData(fn)
{
this.FirstName=fn;
}
};
document.write(student.FirstName);
student.putData='Vishal';
document.write(student.FirstName);
</script>
</body>
</html>
 In the above example, the setter method is used to change the value of an object.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 10
CSS/JavaScript Important Questions

14. Explain prompt() and confirm() method of Java script 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>
<body>
<script type="text/javascript">
function msg()
{
var v= prompt("Who are you?");
alert("I am "+v);
}
</script>
<input type="button" value="click" onclick="msg()"/>
</body>
</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>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 11
CSS/JavaScript Important Questions

15. Write a Java script program which computes, the average marks of the following students
then, this average is used to determine the corresponding grade.

<html>
<body>
<script language="javascript" type="text/javascript">
var students = [['Summit', 80], ['Kalpesh', 77], ['Amit', 88], ['Tejas',
93],['Abhishek', 65]];
var total = 0;
for (var i=0; i < students.length; i++)
{
total += students[i][1];
}
var avg = (total/students.length);
document.write("Average Marks: " + avg);
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>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 12
CSS/JavaScript Important Questions

</html>

16. Write the use of chatAt() and indexof() with syntax and example.
charAt()
 The charAt() method requires one argument i.e is the index of the character that you
want to copy.
 Syntax:
SingleCharacter = NameOfStringObject.charAt(index);
 Example: var FirstName = 'Vishal';
var Character = FirstName.charAt(0); //V

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 = 'Vishal’;

var IndexValue = FirstName.indexOf('i'); // 1

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


concat() join()
Array elements can be combined by using Array elements can be combined by using
concat() method of Array object. join() method of Array object.
The concat() method separates each value with a The join() method also uses a comma to
comma. separate values, but you can specify a
character other than a comma to separate
values.
Syntax: string.concat(str1, str2, ..., strN) Syntax: array.join(separator)
Eg: Eg:
cars=new Array{'BMW', Audi', 'Maruti'} cars=new Array{'BMW', Audi', 'Maruti'}
var str = cars.concat() var str = cars.join(' ')
The value of str is 'BMW, Audi, Maruti' The value of str in this case is 'BMW Audi
Maruti'

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 13
CSS/JavaScript Important Questions

18. Write a JavaScript that will replace following specified value with another value in string.
String = “I will fail”
Replace “fail” by “pass”
<html>
<body>
<script>
var myStr = "I will fail";
var newStr = myStr.replace("fail", "pass");
document.write(newStr);
</script>
</body>
</html>

19. Write a Java Script code to display 5 elements of array in sorted order.
<html>
<body>
<script>
var arr1 = [ “Red”, “red”, “Blue”, “Green”]
document.write(“Before sorting arra1=” + arr1);
document.write(“<br>After sorting arra1=” + arr1.sort());
</script>
</body>
</html>

20. Explain open() method of window object with syntax and example.
 The open() method of window object is used to open a new window and loads the
document specified by a given URL.
MyWindow = window.open()
 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.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 14
CSS/JavaScript Important Questions

 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')

<html>
<head>
<script language="javascript" type="text/javascript">
function DisplayNewWindow()
{
var x1=window.open("https://www.msbte.org.in","w1","top=200,left=100,width=500,height=500");
}
</script>
</head>
<body>
<form name="myform">
<input type="button" name="b1" value="Show New Window" onclick="DisplayNewWindow()">
</form>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 15
CSS/JavaScript Important Questions

21. Describe regular expression. Explain search () method used in regular expression with suitable
example.
Regular Expression:
 A regular expression is very similar to a mathematical expression, except a regular
expression tells the browser how to manipulate text rather than numbers by using
special symbols as operators.

Search() method:

 str.search() method takes a regular expression/pattern as argument and search for the
specified regular expression in the string.
 This method returns the index where the match found.

Example:

<html>
<body>
<script>
function myFunction()
{
var str = "Good Morning!";
var regEx=/Morning/i;
var n = str.search(regEx);
document.write(n);
}
myFunction();
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 16
CSS/JavaScript Important Questions

22. 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.

Disabling the right Mouse Button

- We have seen security concern of javascript.

- Also, we know that by using mouse button we can open the web page source code including
javascript code.

- So, we need to take proper action on this point so that hacker cannot see our code.

- Viewing source code by user is not safe hence disabling right mouse button is important.

<html>
<head>
<script language="javascript" type="text/javascript">
function display()
{
document.addEventListener('contextmenu',event=>event.preventDefault());
}
</script>
</head>
<body>
<input type="button" name="b1" value="Protect Web Page" onclick="display()">
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 17
CSS/JavaScript Important Questions

23. Create a slideshow with the group of three images, also simulate next and previous transition
between slides in your Java Script.
<html>
<body>
<img src="Apple.png" width="500" height="300" id="image1"> <br><br><br><br>
<input type="button" value="Previous" onclick="SlideShow(-1)">
<input type="button" value="Next" onclick="SlideShow(1)">

<script language="javascript" type="text/javascript">


Image_Array=new Array("img1.png","img2.png","img3.png");
i=0;
function SlideShow(status)
{
i=i+status;
if(i>(Image_Array.length-1))
{
i=0;
}
if(i<0)
{
i=Image_Array.length-1;
}
document.getElementById("image1").src=Image_Array[i];
}
</script>

</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 18
CSS/JavaScript Important Questions

24. Explain text rollover with suitable example.


 You create a rollover for text by using the onmouseover attribute of the tag, which is the
anchor tag.
 You assign the action to the onmouseover attribute.
 We have created rollover projects for fruit images.
 When the user rolls the mouse cursor over the fruit name then the image of the flower
is displayed.
 Example.
<html>
<body>
<h1> Image Rollover </h1><br><br>
<h2>
<a onmouseover="document.vjtech.src='Apple.png'">Apple</a> <br><br>
<a onmouseover="document.vjtech.src='PineApple.png'">PineApple</a> <br><br>
<a><img src="css.png" name="vjtech"></a>
</h2>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 19
CSS/JavaScript Important Questions

25. Write a Java script to modify the status bar using on MouseOver and on MouseOut with links.
When the user moves his mouse over the 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.
<html>
<head>
<title>JavaScript Status Bar</title>
</head>
<body>
<a href="https://msbte.org.in/" onMouseOver="window.status='MSBTE'"
onMouseOut="window.status="> MSBTE </a>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 20
CSS/JavaScript Important Questions

26. 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>
<body>
<form name="myform" action="" method="post">
<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>
</form>
<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";

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 21
CSS/JavaScript Important Questions

optionList[2].value=3;
}
}
}
</script>
</body>
</html>

27. Describe, how to read cookie value and write a cookie value. Explain with example.
 Web Browsers and Servers use HTTP protocol to communicate and HTTP is a stateless
protocol.
 But for a commercial website, it is required to maintain session information among
different pages. For example, one user registration ends after completing many pages.
But how to maintain users' session information across all the web pages.
 Cookies are a plain text data record of 5 variable-length fields
o Expires − The date the cookie will expire. If this is blank, the cookie will expire when
the visitor quits the browser.
o Domain − The domain name of your site.
o Path − The path to the directory or web page that set the cookie. This may be blank
if you want to retrieve the cookie from any directory or page.
o Secure − If this field contains the word "secure", then the cookie may only be
retrieved with a secure server. If this field is blank, no such restriction exists.
o Name=Value − Cookies are set and retrieved in the form of key-value pairs
 Cookies were originally designed for CGI programming. The data contained in a cookie is
automatically transmitted between the web browser and the web server, so CGI scripts on
the server can read and write cookie values that are stored on the client.
 JavaScript can also manipulate cookies using the cookie property of the Document object.
JavaScript can read, create, modify, and delete the cookies that apply to the current web
page.
 Example:

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 22
CSS/JavaScript Important Questions

<html>
<head>
<script language="javascript" type="text/javascript">
function WriteCookie()
{
var nm=document.getElementById("id1").value;
document.cookie="name="+nm+";expires=Sun, 31 Jan 2023 00:00:00 GMT";
alert("Cookie Written Successfully");
}
function ShowCookie()
{
var x=document.cookie;
alert(x);
}
</script>
</head>
<body>
<form name="myform">
Enter Your Name:<input type="text" name="tf1" id="id1">
<input type="button" name="b1" value="Create Cookie" onclick="WriteCookie()">
<input type="button" name="b2" value="Get Cookie" onclick="ShowCookie()">
</form>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 23
CSS/JavaScript Important Questions

28. 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.
 Example:
<html>
<body>
<form name="myform">
Select your favourite Programming Language:<br>
<input type="checkbox" name="c1" id="id1" value="c lang">C Lang
<input type="checkbox" name="c2" id="id2" value="c++ lang">C++ Lang
<input type="checkbox" name="c3" id="id3" value="java lang">Java Lang
<input type="checkbox" name="c4" id="id4" value="python lang">Python Lang
<input type="button" name="b1" value="Show" onclick="EvaluateChecbox()">

</form>
<script language="javascript" type="text/javascript">
function EvaluateChecbox()
{
var m="You have selected: ";
if(document.getElementById("id1").checked==true)
{
m=m+document.getElementById("id1").value+" ";
}
if(document.getElementById("id2").checked==true)
{
m=m+document.getElementById("id2").value+" ";
}
if(document.getElementById("id3").checked==true)
{
m=m+document.getElementById("id3").value+" ";
}
if(document.getElementById("id4").checked==true)

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 24
CSS/JavaScript Important Questions

{
m=m+document.getElementById("id4").value+" ";
}
alert(m);
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 25
CSS/JavaScript Important Questions

29. Write a script for creating following frame structure. 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.

<html>
<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>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 26
CSS/JavaScript Important Questions

30. 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>
<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>
</select>
</form>
<script language="javascript" type="text/javascript">
function getPage(choice)
{
page=choice.options[choice.selectedIndex].value;
if(page!= "")
{
window.location=page;
}
}
</script>

</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 27
CSS/JavaScript Important Questions

31. Write the syntax of and explain use of following methods of JavaScript Timing Event.
a. setTimeout()
b. setInterval()
- Window objects provide predefined timer functions which allow you to register function to be
invoked once or any no of times depending upon specified time.
- In JavaScript, we can write some code that will execute at specified time intervals. This is called
timing events.

1) var id=setTimeout(function,delay) - It will initiates a single timer which will call the specified
function after the delay. This function return unique id with which the timer can be canceled at
a later time.

2) var id=setInterval(function,delay) - Similar to setTimeout method but it will call the function
continually until it canceled. This method will help us to execute function which you want to call
again and again.

3) clearInterval(id) - It is used to stop timer.

4) clearTimeout(id) - It is used to stop timer.

Program:
-------------
<html>
<head>
<script language="javascript" type="text/javascript">
var number=0;
var timerID=null;
function WriteNos()
{
if(timerID==null)
{
timerID=setInterval("display()",500);
}
}
function display()
{
if(number<=15)
{
document.getElementById("id1").innerHTML+=number+" ";
number=number+1;
}
else
{
clearInterval(timerID);
}

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 28
CSS/JavaScript Important Questions

}
</script>
</head>
<body>
<input type="button" name="b1" value="Click Me" onclick="WriteNos()">
<textarea name="ta1" id="id1" rows=5 cols=20></textarea>
</body>
</html>

32. Write a java script that displays textboxes for accepting name & email ID & a submit button.
Write java script code such that when the user clicks on submit button (1) Name Validation (2)
Email ID Validation.
<html>
<body>
<form name="myform">
Enter Your Name:<input type="text" name="tf1">
Enter Email ID:<input type="text" name="tf2">
<input type="button" Value="Validation" onclick="ValidateForm()">
</form>
<script>
function ValidateForm()
{
if(document.myform.tf1.value=="")
{
alert( "Please provide your name!" );
}
else if(document.myform.tf2.value=="")
{
alert("Please provide your Email!" );
}
else
{
var emailID =document.myform.tf2.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
alert("Please enter correct email ID")
}
else
{
alert("Validation done successfully");
}
}
}
</script>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 29
CSS/JavaScript Important Questions

</body>
</html>

33. Write a javascript program to demonstrate java intrinsic function


<html>
<body>
<form name="myform">
First Name:<input type="text" name="fname"><br>
Last Name:<input type="text" name="lname"><br>
<img src="submit.png" onclick="javascript:document.forms.myform.submit()">
<img src="reset.png" onclick="javascript:document.forms.myform.reset()">
</form>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 30
CSS/JavaScript Important Questions

34. 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.
<html>
<body>
<form name="myform">
Enter User Name:<input type="text" name="tf1" id="id1">
Enter Password:<input type="text" name="tf2" id="id2">
<input type="button" name="b1" value="Create Cookie" onclick="WriteCookie()">
</form>
<script language="javascript" type="text/javascript">
function WriteCookie()
{
var nm=document.getElementById("id1").value;
var val=document.getElementById("id2").value;
document.cookie=nm+"="+val+";expires=Tues,31 Jan 2024 00:00:00 GMT";
alert("Cookie Written Successfully");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 31
CSS/JavaScript Important Questions

35. Write a javascript program to create read, update and delete cookies.
<html>
<body>
<form name="myform">
Enter Name of Cookie:<input type="text" name="tf1" id="id1">
Enter Value of Cookie:<input type="text" name="tf2" id="id2">
<input type="button" name="b1" value="Create Cookie" onclick="WriteCookie()">
<input type="button" name="b2" value="Read Cookie" onclick="ReadCookie()">
<input type="button" name="b3" value="Update Cookie" onclick="UpdateCookie()">
<input type="button" name="b4" value="Delete Cookie" onclick="DeleteCookie()">
</form>
<script language="javascript" type="text/javascript">
function WriteCookie()
{
var nm=document.getElementById("id1").value;
var val=document.getElementById("id2").value;
document.cookie=nm+"="+val+";expires=Tues,31 Jan 2024 00:00:00 GMT";
alert("Cookie Written Successfully");
}
function ReadCookie()
{
var x=document.cookie;
alert(x);
}
function UpdateCookie()
{
var nm=document.getElementById("id1").value;
var val=document.getElementById("id2").value;
document.cookie=nm+"="+val+";expires=Tues,31 Jan 2024 00:00:00 GMT";
alert("Cookie updated Successfully");
}
function DeleteCookie()
{
var nm=document.getElementById("id1").value;
var val=document.getElementById("id2").value;
document.cookie=nm+"="+val+";expires=Tues,31 Jan 1999 00:00:00 GMT";
alert("Cookie deleted Successfully");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 32
CSS/JavaScript Important Questions

36. Q.1 Write a javascript program to link banner advertisements to different URLs.
Q.2 Develop a JavaScript Program to Create Rotating Banner Ads with URL Links
<html>
<body onload="ShowBanners()">
<a href="javascript:ShowLinks()">
<img src="clang.jpg" width="500" height="300" name="ChangeBanner"/>
</a>
<script language="Javascript">
MyBanners=new Array('clang.png','cpp.png','java.png')
MyBannerLinks=new
Array('http://msbte.org.in','http://www.google.com','http://www.gmail.com')
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>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 33
CSS/JavaScript Important Questions

37. 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.
<html>
<body>
<form name="myform">
Enter 1st No:<input type="text" id="tf1">
Enter 2nd No:<input type="text" id="tf2">
Result:<input type="text" id="tf3">
<input type="button" name="b1" value="ADD" onclick="Addition()">
<input type="button" name="b2" value="SUB" onclick="Subtraction()">
<input type="button" name="b3" value="DIV" onclick="Division()">
<input type="button" name="b4" value="MUL" onclick="Multiplication()">
</form>
<script language="javascript">
function Addition()
{
var a=parseInt(document.getElementById("tf1").value);
var b=parseInt(document.getElementById("tf2").value);
var c=a+b;
document.getElementById("tf3").value=c;
}
function Subtraction()
{
var a=parseInt(document.getElementById("tf1").value);
var b=parseInt(document.getElementById("tf2").value);
var c=a-b;
document.getElementById("tf3").value=c;
}
function Division()
{
var a=parseInt(document.getElementById("tf1").value);
var b=parseInt(document.getElementById("tf2").value);
var c=a/b;
document.getElementById("tf3").value=c;
}
function Multiplication()
{
var a=parseInt(document.getElementById("tf1").value);
var b=parseInt(document.getElementById("tf2").value);
var c=a*b;
document.getElementById("tf3").value=c;
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 34
CSS/JavaScript Important Questions

38. Develop javascript to convert the given character to unicode and vice-versa
<html>
<body>
<script language="javascript" type="text/javascript">
var str="MSBTE";
document.write("ASCII Value of B="+str.charCodeAt(2)); //66
document.write("<br>Character Value of ASCII 65="+String.fromCharCode(65)); //A
</script>
</body>
</html>

39. Write a javascript function to generate Fibonacci series till user defined limit.
<html>
<body>
<script language="javascript" type="text/javascript">
function DisplayFibonancci()
{
var fno=0, sno=1, tno;
var no=parseInt(prompt("Enter Value of no"));
document.write("Fibonancci Series:"+fno+"\t"+sno);
for(i=2;i<no;i++)
{
tno=fno+sno;
document.write("\t"+tno);
fno=sno;
sno=tno;
}
}
DisplayFibonancci();
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 35
CSS/JavaScript Important Questions

40. State what is regular expression. Explain its meaning with the help of a suitable example.
 A regular expression is an object that describes a pattern of characters.
 Regular expressions are used to perform pattern-matching and "search-and-replace"
functions on text.
 Syntax

/pattern/modifiers;

 Example:

/msbte/i is a regular expression.



msbte 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:

Description
Modifier

g Perform a global match (find all matches rather than stopping


after the first match)

i Perform case-insensitive matching

m Perform multiline matching

Program:
<html>
<body>
<script language="javascript" type="text/javascript">
function CheckOperation()
{
var regex=/vjtech/gmi;
var str=document.getElementById("tf1").value;
var result=regex.test(str);
alert("Regular Expression Result:"+result);
}
</script>
Enter Text:<input type="text" id="tf1">
<input type="button" name="b1" value="Check" onclick="CheckOperation()">
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 36
CSS/JavaScript Important Questions

41. Write a JavaScript function that accepts a string as a parameter and find the length of the
string.
<html>
<body>
Enter Any Text:<input type="text" id="tf1">
<input type="button" name="b1" value="Find Length" onclick="CalcLength()">
<script language="javascript" type="text/javascript">
function CalcLength()
{
var str=document.getElementById("tf1").value;
var i=0;
var len=0;
while(str[i]! =null)
{
len++;
i++;
}
document.write("<br>Length of String="+len);
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 37
CSS/JavaScript Important Questions

42. Write a javascript program to validate email ID of the user using regular expression.
<html>
<body>
Enter Text:<input type="text" id="tf1">
<input type="button" name="b1" value="Validate" onclick="validateEmail()">
<script language="javascript" type="text/javascript">
function validateEmail()
{
var regex= /^ [a-zA-Z0-9_.] +\@[a-z] +\. +[a-z] {2,3} $/
var str=document.getElementById("tf1").value;
var result=regex.test(str);
if(result)
{
alert("Valid email id");
}
else
{
alert("Invalid email id");
}
}
</script>
</body>
</html>

43. Write a javascript to checks whether a passed string is palindrome or not.


<html>
<body>
<script language="javascript" type="text/javascript">
function checkPalindrome(str)
{
var len = str.length;
for (var i=0;i<len/2;i++)
{
if(str[i]!==str[len-1-i])
{
return "String is not a palindrome";
}
}
return 'String is a palindrome';
}
var str = prompt('Enter a string: ');
var value = checkPalindrome(str);
alert(value);
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 38
CSS/JavaScript Important Questions

44. 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.

<html>
<head>
</head>
<body>
<img src="Apple.png" width="500" height="300" id="image1">
<input type="button" value="Previous" onclick="SlideShow(-1)">
<input type="button" value="Next" onclick="SlideShow(1)">

<script language="javascript" type="text/javascript">


Image_Array=new Array ("img1.png","img2.png", "img3.png","img4.png", "img5.png",
"img6.png);
i=0;
function SlideShow(status)
{
i=i+status;
if(i>(Image_Array.length-1))
{
i=0;
}
if(i<0)
{
i=Image_Array.length-1;
}
document.getElementById("image1").src=Image_Array[i];
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 39
CSS/JavaScript Important Questions

45. List and explain Logical operators in JavaScript.


Logical Operators:
- The following operators are known as JavaScript logical operators.

- Example:
<html>
<body>
<script type = "text/javascript">
var a = true;
var b = false;
document.write("(a && b) => ");
result = (a && b);
document.write(result);
document.write("<br>");

document.write("(a || b) => ");


result = (a || b);
document.write(result);
document.write("<br>");

document.write("!(a && b) => ");


result = (!(a && b));
document.write(result);
document.write("<br>");
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 40
CSS/JavaScript Important Questions

46. Write a JavaScript that identifies a running browser.


<html>
<body>
<script type="text/javascript">
var name = navigator.userAgent;
if(name.indexOf("Chrome")!= -1)
{
document.write("Google Chrome");
}
else if(name.indexOf("Firefox")!=-1)
{
document.write("Mozilla Firefox");
}
else if(name.indexOf("Opera")!=-1)
{
document.write("Opera");
}
else if (name.indexOf("MSIE")!=-1)
{
document.write("Internet Explorer");
}
else if (name.indexOf("Safari")!=-1)
{
document.write("Safari");
}
else
{
document.write("unknown browser");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 41
CSS/JavaScript Important Questions

47. Write a JavaScript that displays all properties of window object. Explain the code.
Program:
<html>
<body>
<script type="text/javascript">
for (var X in window)
{
document.write("<br>"+X);
}
</script>
</body>
</html>

Explanation of code:
- In above code, we have tried to display all properties of window object.
- Window is a predefined object of browser.
- In this code, we have tried to use for in loop which will iterate over the all properties of
window object.
- Window object property will assign to variable ‘X’ one bye one and inside the body of loop it
will display on browser.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 42
CSS/JavaScript Important Questions

48. Write a JavaScript function to count the number of vowels in a given string

<html>
<body>
<script language="javascript" type="text/javascript">
var vowels = ["a", "e", "i", "o", "u"]
function countVowel(str)
{
var count=0;
str=str.toLowerCase();
for (letter of str)
{
if (vowels.includes(letter))
{
count++;
}
}
alert("No of Vowels:"+count);
}
var x = prompt("Enter a string:");
countVowel(x);
</script>
</body>
</html>

49. 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>

<body>

<script language="javascript" type="text/javascript">

var ColorName=prompt("Enter Color:");

document.body.style.background = ColorName;

</script>

</body>

</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 43
CSS/JavaScript Important Questions

50. 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. 3
ii) ii) Constructs the mailID as [email protected] and displays mail ID as message. (Ex. If
user enters Rajni as name and Pathak as surname mailID will be constructed as
[email protected]) .

<html>
<body>
Enter First Name:<input type="text" id="tf1"><br>
Enter Middle Name:<input type="text" id="tf2"><br>
Enter Surname:<input type="text" id="tf3"><br>
<input type="button" name="b1" value="Submit" onclick="display()">

<script language="javascript" type="text/javascript">


function display()
{
var firstname=document.getElementById("tf1").value;
var surname=document.getElementById("tf3").value;
var email_id=firstname+"."+surname+"@msbte.com";
alert("Email id: "+email_id);
document.getElementById("tf1").disabled = true;
document.getElementById("tf2").disabled = true;
document.getElementById("tf3").disabled = true;
document.getElementById("tf1").style.color = "red";
document.getElementById("tf2").style.color = "red";
document.getElementById("tf3").style.color = "red";
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 44
CSS/JavaScript Important Questions

51. Write a JavaScript that displays first 20 even numbers on the document window.

<html>
<body>
<script language="javascript" type="text/javascript">
document.write("First 20 even numbers:");
for(i=1;i<=40;i++)
{
if(i%2==0)
{
document.write("<br>"+i);
}
}
</script>
</body>
</html>

52. Write a program to print sum of even numbers between 1 to 100 using for loop.

<html>
<body>
<script language="javascript" type="text/javascript">
var sum=0;
for(i=1;i<=100;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
document.write("Sum of EVEN numbers between 1 to 100 :"+sum);
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 45
CSS/JavaScript Important Questions

53. Write a JavaScript function to insert a string within a string at a particular position

<html>

<body>

<script language="javascript" type="text/javascript">

var a = prompt("Enter any String:");

var b = " "+prompt("Enter String for insertion:");

var position = parseInt(prompt("Enter position for insertion:"));

var output = [a.slice(0, position), b, a.slice(position)].join('');

alert(output);

</script>

</body>

</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 46
CSS/JavaScript Important Questions

54. Design the frameset tag for following frame layout:

Webpage1.html
<html>
<body>
<center><h1>Frame1</h1></center>
</body>
</html>

Webpage2.html
<html>
<body>
<center><h1>Frame2</h1></center>
</body>
</html>

Webpage3.html
<html>
<body>
<center><h1>Frame3</h1></center>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 47
CSS/JavaScript Important Questions

MainWebPage.html
<html>
<head>
<frameset rows="25%,50%,25%">
<frame src="webpage1.html" />
<frame src="webpage2.html" />
<frame src="webpage3.html" />
</frameset>
</head>
</html>

55. Write a JavaScript program that create a scrolling text on the status line of a window.
<html>
<body>
<input type="button" name="b1" value="Status Bar" onclick="scrollText('Welcome to
status bar')">
<script language="javascript" type="text/javascript">
var scrollpos=0;
var maxscroll=100;
var blanks="";
function scrollText(text)
{
window.setInterval(displayText(text),500);
}
function displayText(text)
{
window.status=blanks+text;
++scrollpos;
blanks+=" ";
if(scrollpos>maxscroll)
{
scrollpos=0;
blanks="";
}
}
</script>

</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 48
CSS/JavaScript Important Questions

56. Write a JavaScript that find and displays number of duplicate values in an array.
<html>
<body>
<script>
var array = [6, 9, 15, 6, 13, 9, 11, 15,100,100];
var index = 0, newArr = [];
var length = array.length;

function findDuplicates(arr)
{
for(var i=0;i<length-1;i++)
{

for(var j=i+1;j<length;j++)
{
if(arr[i]===arr[j])
{
newArr[index]=arr[i];
index++;
break;
}
}
}
document.write("Duplicates Value of Array:"+newArr);
}
findDuplicates(array);
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 49
CSS/JavaScript Important Questions

57. Construct regular expression for validating the phone number in following format only : (nnn)-
nnnn-nnnn OR nnn.nnnn.nnnn

<html>
<body>
Enter Mobile No:<input type="text" id="id1">
<input type="button" value="Validate" onclick="validation()">

<script>
function validation()
{
var regexp=/\([0-9]{3}\)\-[0-9]{3}\-[0-9]{3}\-[0-9]{4}/;
var x=document.getElementById("id1").value;
if(regexp.test(x))
{
window.alert("Valid Mobile no.");
}
else
{
window.alert("Invalid Mobile no.");
}
}
</script>

</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 50
CSS/JavaScript Important Questions

58. Write HTML Script that displays dropdown list 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>
<body>
<form name="myform">
Select Your Favourite City:
<select name="MenuChoice" onchange="getImage(this.value)">
<option value="city1.png">NewDelhi</option>
<option value="city2.png">Mumbai</option>
<option value="city3.png">Bangalore</option>
</select><br><br>
<table border="1">
<tr>
<td>
<img src="" id="id1" width="250" height="250"><br><br>
</td>
</tr>
<tr>
<td>
<p id="id2"></p>
</td>
</tr>
</table>
</form>
<script language="javascript" type="text/javascript">
function getImage(img)
{
if(img=="city1.png")
{
document.getElementById("id1").src=img;
document.getElementById("id2").innerHTML="This is capital city of India";
}
else if(img=="city2.png")
{
document.getElementById("id1").src=img;
document.getElementById("id2").innerHTML="This is capital city of
Maharashtra";
}
else if(img=="city3.png")
{
document.getElementById("id1").src=img;
document.getElementById("id2").innerHTML="This is capital city of Karnataka";
}
}

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 51
CSS/JavaScript Important Questions

</script>
</body>
</html>

59. 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).
<html>
<body>
Enter Aadhar No:<input type="text" id="id1">
<input type="button" value="Validate" onclick="validation()">
<script>
function validation()
{
var regexp= /^[0-9]{4}[.-]?[0-9]{4}[ .-]?[0-9]{4}$/;
var x=document.getElementById("id1").value;
if(regexp.test(x))
{
window.alert("Valid Aadhar no.");
}
else
{
window.alert("Invalid Aadhar no.");
}
}
</script>

</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 52
CSS/JavaScript Important Questions

60. Write a javascript to create option list containing list of images and then display images in
new window as per selection.
<html>
<body>
<form name="myform">
Select Your Favourite Image:
<select name="MenuChoice" onchange="getImage(this.value)">
<option value="city1.png">Mumbai</option>
<option value="city2.png">Pune</option>
<option value="city3.png">Thane</option>
</select>
</form>
<script language="javascript" type="text/javascript">
function getImage(img)
{
window.open(img,"vjtech","width=500,height=500 top=100 left=100");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 53
CSS/JavaScript Important Questions

61. Differentiate between For-loop and For-in loop.

62. State the use of dot syntax in JavaScript with the help of suitable example.
 In JavaScript, you refer to the methods and properties of an object using the Dot Syntax.
 When you do this, you must include the name of the object. JavaScript uses the Dot Syntax
to separate the name of the object from its properties and methods.
 One of the best example is: - document. write("Hello World! ");
 Here you are using the method write () of the document object

63. State and explain what is a session cookie?

 A session Cookies Contain the information that is stored in temporary memory location and
then subsequently deleted after the session is completed or the web browser is closed.
 The main difference between a session and a cookie is that session data is stored data is
stored on the server whereas cookie store data in the visitor browser.
 Session is more secure than cookie as it is stored in server.
64. Enlist and explain the use of any two Intrinsic JavaScript functions.
1) abs() - Returns the absolute value of a number.
2) exp() - Returns E'N Where N is the argument, and E is Euler's Constant, the base of the
natural logarithm.

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 54
CSS/JavaScript Important Questions

65. Write a JavaScript function to check whether a given value is valid IP value or not
<html>
<body>
<script>
var ipaddr = prompt("Enter IP Address:");
var pattern = /^[0-255]{1,3}\.[0-255]{1,3}\.[0-255]{1,3}\.[0-255]{1,3}$/;
// format for ip address range 0.0.0.0 to 255.255.255.255
var result = pattern.test(ipaddr);
if(result)
{
alert("IP Address is Valid");
}
else
{
alert("IP Address is Invalid");
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 55
CSS/JavaScript Important Questions

66. Write a javascript program to validate user accounts for multiple set of user ID and password
(using swith case statement).
<html>
<body>
Enter User ID :<input type="number" id="tf1">
Enter Password: <input type="password" id="tf2">
<input type="button" value="Validate" onclick="validateUser()">
<script>
function validateUser()
{
var userid=document.getElementById("tf1").value;
var psw=document.getElementById("tf2").value;
switch(userid,psw)
{
case 1010,"msbte1": alert("User account is valid");
break;
case 2020,"msbte2": alert("User account is valid");
break;
case 3030,"msbte3": alert("User account is valid");
break;
default: alert("No user details found")
break;
}
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 56
CSS/JavaScript Important Questions

67. Write a javascript program to design HTML page with books information in tabular format,
use rollovers to display the discount information.
<html>
<body>
<table id="bookTable" border="1">
<tr>
<th>BOOKID</th>
<th>NAME</th>
<th>PRICE</th>
<th>DISCOUNT</th>
</tr>
<tr>
<td>1010</td>
<td>C++</td>
<td>550</td>
<td id="discount1">10%</td>
</tr>
<tr>
<td>2020</td>
<td>Java</td>
<td>350</td>
<td id="discount2">15%</td>
</tr>
</table>
<script>
var discount1 = document.getElementById("discount1");
var discount2 = document.getElementById("discount2");
discount1.onmouseover = function()
{
discount1.innerHTML = "Buy one get one free!";
}
discount1.onmouseout = function()
{
discount1.innerHTML = "10%";
}
discount2.onmouseover = function()
{
discount2.innerHTML = "Buy two get one free!";
}
discount2.onmouseout = function()
{
discount2.innerHTML = "15%";
}
</script>
</body>
</html>

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 57
CSS/JavaScript Important Questions

“ALL THE BEST FOR YOUR EXAM”

VJTECH ACADEMY, MAHARASHTRA

JavaScript IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 58

You might also like