Javascript Multiple Choice Questions and Answers-Sheet 1
Javascript Multiple Choice Questions and Answers-Sheet 1
2. When a user views a page containing a JavaScript program, which machine actually executes the
script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above
Ans: A
6. _____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-
clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A
11. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A
13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above
Ans: A
17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
Ans: C
19. Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above
Ans: A
22. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the
paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
Ans: B
23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D
28. ______method evaluates a string of JavaScript code in the context of the specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A
29. Which of the following event fires when the form element loses the focus: <button>, <input>,
<label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B
32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B
35. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D
36. To set up the window to capture all Click events, we use which of the following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A
39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C
40. In JavaScript, _________ is an object of the target language data type that encloses an object of
the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A
41. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
42. _______ class provides an interface for invoking JavaScript methods and examining JavaScript
properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A
44. A ________ object is a reference to one of the classes in a Java package, such as
netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B
45. The JavaScript exception is available to the Java code as an instance of __________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
Ans: B
46. To automatically open the console when a JavaScript error occurs which of the following is added
to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D
47. To open a dialog box each time an error occurs, which of the following is added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
Ans: A
49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C
Output------?
A. 44
B. 8
C. 4
D. Error output
Ans: A
53. <script>
document.write(navigator.appCodeName);
</script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Ans: A
Output------?
a) 44
b) 8
c) 4
d) Error output
4) <script>
document.write(navigator.appCodeName);
< /script>
a) get code name of the browser of a visitor
b) set code name of the browser of a visitor
c) None of the above
8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
20) parseFloat(9+10)=?
a) 19
b) 910
c) None
</script>
a) hello
b) bye
c) Error in string handling
d) None of the above
26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
27) How do you create a new object in JavaScript?
a) var obj = {};
b) var obj = Object();
c) var obj=new {};
d) None of the above
29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5
31) Choose the four symbol pairs that represent RegExp properties lastMatch, lastParent,
leftContext, and rightContext, respectively:
a) $&, $+, $`, $'
b) $+, $&, $', $`
c) $&, $~, $`, $'
d) $+, $&, $`, $'
32) Which of the following properties hold the values of the pixels of the length of the width
and height of the viewer's screen resolution?
a) screen.width and screen.height
b) Resolution.width and Resolution.height
c) screen.pixels.width and screen.pixels.height
d) ViewerScreen.width and ViewerScreen.height
33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150
</script>
a) in in In
b) in in in
c) in in null
d) in null null
a) first
b) undefined
c) First
d) Error
51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":
59) In Javascript, Which of the following method is used to find out the character at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()
</script>
a) Po
b) yP
c) oi
d) P
64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
d) for , while loop
67) In javascript, RegExp Object Method test() is used to search a string and returns
_________
a) true or false
b) found value
c) index
d) None of the above
68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href
Question:
In javascript, which of the above statement can used for string declaration ?
</script>
a) in in In
b) in in in
c) in in null
d) in null null
73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80
76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error
Ans: B
Ans: A
A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: B
A. Microsoft
B. Navigator
C. LiveWire
D. Native
Ans: C
B. Varying randomly
Ans: A
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A
A. The </script>
B. The <script>
Ans: A
Ans: C
A. Return a value
C. Accept parameters
Ans: C
A. 2names
B. _first_and_last_names
C. FirstAndLast
Ans: A
11. ______ tag is an extension to HTML that can enclose any number of
JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A
12. How does JavaScript store dates in a date object?
Ans: A
13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
Ans: A
A. System.out.println("Hello World")
C. document.write("Hello World")
D. response.write("Hello World")
Ans: C
15. Which of the following way can be used to indicate the LANGUAGE
attribute?
A. <LANGUAGE="JavaScriptVersion">
B. <SCRIPT LANGUAGE="JavaScriptVersion">
Ans: C
A. <js>
B. <scripting>
C. <script>
D. <javascript>
Ans: C
17. What is the correct syntax for referring to an external script called " abc.js"?
Ans: C
Ans: B
19. Which of the following navigator object properties is the same in both
Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
Ans: A
Ans: C
Ans: A
22. If para1 is the DOM object for a paragraph, what is the correct syntax to
change the text within the paragraph?
A. "New Text"?
B. para1.value="New Text";
D. para1.nodeValue="New Text";
Ans: B
23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D
Ans: D
A. FileUpLoad
B. Function
C. File
D. Date
Ans: C
A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D
A. new
B. this
C. delete
D. typeof
Ans: B
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A
29. Which of the following event fires when the form element loses the focus:
<button>, <input>, <label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B
A. [objectName.]eval(numeriC.
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeriC.
Ans: B
B. Server
C. Object
Ans: A
32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B
Ans: C
B. dateObjectName.new Date([parameters])
D. dateObjectName Date([parameters])
Ans: A
35. The _______ method of an Array object adds and/or removes elements from an
array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D
36. To set up the window to capture all Click events, we use which of the
following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A
A. <IMG>
B. <A>
C. <BR>
Ans: B
A. Pathname
B. Protocol
C. Defaultstatus
D. Host
Ans: C
39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C
40. In JavaScript, _________ is an object of the target language data type that
encloses an object of the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A
41. When a JavaScript object is sent to Java, the runtime engine creates a Java
wrapper of type ___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
42. _______ class provides an interface for invoking JavaScript methods and
examining JavaScript properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A
44. A ________ object is a reference to one of the classes in a Java package, such
as netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
Ans: B
46. To automatically open the console when a JavaScript error occurs which of the
following is added to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D
47. To open a dialog box each time an error occurs, which of the following is
added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
Ans: A
A. Blur()
B. Blur(contrast)
C. Blur(value)
D. Blur(depth)
Ans: A
49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C
B. Close(object)
C. Close(val)
D. Close()
Ans: D
A. 44
B. 8
C. 4
D. Error output
Ans: A
A. True B. False
Ans: A
Ans: A
Ans: C
A. Database
B. Cursor
C. Client
D. FileUpLoad
Ans: D
Ans: A
A. False B. True
Ans: A
B. Error
C. 7
D. 78
Ans: D
A. 9123
B. 91234
C. 80000
Ans: A
a) 44
b) 8
c) 4
d) Error output
document.write(result);
</script>
a) Quality
b) Q,u,a,l,i,t,y,P,o,i,n,t,T,e,c,h,n,o,l,o,g,i,e,s
c) Qualiyt,Point,Technologies
d) QualityPointTechnologies
a) True
b) False
4) <script>
document.write(navigator.appCodeName);
< /script>
Show Answer
8) <script language="javascript">
function x()
document.write(output);
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
9) <script language="javascript">
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
a) Database
b) Cursor
c) Client
d) FileUpLoad
a) NO
b) YES
a) (a) only
b) (b) only
function x(z,t)
alert(x.length);
< /script>
output:
?
a) Error
b) 2
c) 1
d) 3
a) False
b) True
c) None of above
a) 20
b) -21
c) 19
d) None
a) %,!,{,[,!,!
b) Q,u,a,l,i,t,y,1,0,0
c) Quality 100
d) Error
qpt[0] = "WebDevelopment";
qpt[1]="ApplicationDevelopment"
qpt[2]="Testing"
qpt[3] = "QualityPointTechnologies";
document.write(qpt[0,1,2,3]);
</script>
a) Error
b) QualityPointTechnologies
c) WebDevelopment
d) WebDevelopmnet,ApplicationDevelopment,Testing,QualityPointTechnologies
a) FileUpLoad
b) Function
c) File
d) Date
20) parseFloat(9+10)=?
a) 19
b) 910
c) None
function x()
{
document.write(2+5+"8");
</script>
a) 258
b) Error
c) 7
d) 78
a) Var
b) Dim
c) String
23) In Javascript, Which of the following method is used to evaluate the regular
expression?
a) eval(2*(3+5))
b) evaluate(2*(3+5))
c) evalu(2*(3+5))
function x()
</script>
a) 100
b) 1,0,0
c) q,u,a,l,i,t,y,%
d) Error
document.write(qpt);
</script>
a) hello
b) bye
a) Error
b) POIiNT
c) Point
d) null
29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5
a) Date
b) Option
c) Layer
d) Checkbox
31) Choose the four symbol pairs that represent RegExp properties lastMatch,
lastParent,
33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150
a) Object signing
b) Style sheets
c) Netcaster channels
d) Image rollovers
a) True
b) False
c) None of above
function x()
var qpt = "We are fast growing Software Company located in Chennai, India.";
} </script>
a) in in In
b) in in in
c) in in null
d) in null null
a) Yes
b) No
a) -21
b) 20
c) -20
d) 21
a) Yes
b) No
function x()
document.write(qpt.match(pattern)[1]);
</script>
a) first
b) undefined
c) First
d) Error
(c). /*......*/ , //
(d). \*......*\ , //
a) Only (d)
b) Only (c)
d) Only (b)
function x()
{
document.write(output);
</script>
a) ,%,!,{,[,!,!
b) G,i,v,e,1,0,0
c) Give 100
d) Error
a) A method
b) A function
c) A statement
d) An operator
var qpt="QualityPointTechnologies";
document.write(result);
</script>
a) 3
b) 18
c) 17
d) 19
function x()
document.write(qpt.match(pattern)[1]);
</script>
a) first
b) First
c) undefined
function sum(x)
function add(y)
return x+y;
return add;
</script>
If you call the function callme(), what will happen ?
a) 10
c) 5
a) Tennis Ritchie
b) James Gosling
c) Brendan Eich
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
</script>
a) No
b) Yes
c) Impossible
a) split()
b) document.clear()
c) join()
d) charAt()
51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":
function x()
</script>
a) Position-7
b) Position-1
c) null
d) error
a) setHours()
b) setMinutes()
c) parse()
a) eval
b) ParseInt
c) ParseFloat
d) None
a) eval
b) parseFloat
c) parseInt
d) None
a) path
b) host
c) secure
d) domain
a) interface
b) short
c) program
d) throws
59) In Javascript, Which of the following method is used to find out the character
at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()
document.write(result);
</script>
a) Po
b) yP
c) oi
d) P
a) Set it to false.
b) Set it to null.
c) Set it to undefined.
d) Set it to -1
a) Yes
b) No
63) JavaScript RegExp Object has modifier 'i' to __________
64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
a) atan()
b) atan2()
c) eval()
d) acos()
document.write(output);
</script>
a) 9123
b) 91234
c) 80000
_________
a) true or false
b) found value
c) index
68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href
Question:
In javascript, which of the above statement can used for string declaration ?
b) Only (a)
d) Only (b)
document.write(result);
</script>
a) 11
b) 12
c) 15
d) 13
function x()
document.write(pattern.exec(s));
</script>
a) Eat
b) eat
c) undefined
d) Eat eat
function x()
var qpt = "We are fast growing Software Company located in Chennai, India.";
a) in in In
b) in in in
c) in in null
d) in null null
73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80
76)<script language="javascript">
function x()
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error
a) tightly
b) loosely
1.Object is also called as : Component
2. which of the following is false about variable name : Variable name is not case sensitive
4. Var mood = Joy + Happiness : Joy is added to Happiness and stored in the variable Mood
8. --------- class is used in javascript for manipulating date and time?: Date
If an exception is thrown
Can appear in both the <head> block and within the <block>
The loop type always runs the enclosed code at least once
1. The triple equal sign === checks for equal value and equal type
{javascript Array: Shift() Method. The shift() method is like the pop() method, only it works at
the beginning of the array. The shift() method pulls the first element off of the given array and
returns it. This alters the array on which the method was called}
while
do-while
For
var el = document.getElementById("awesome");
10. How will you select elements in a page having class
"super" using JavaScript?
For this we will use the document.getElementsByClassName() method.
In the following example we are selecting all the elements in the page having class "super".
<head>
<style>
#header {
background-color: lightgrey;
</style>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
</span>
</td>
</tr>
</table>
<script>
function mul()
</script>
</html>
Control Flow CC: -
<html>
<head>
<style>
#header {
background-color: lightgrey;
</style>
<script type="text/javascript">
function compute(){
var amount = 0;
switch(opt){
amount = (inp*62.04).toFixed(2);
break;
amount = (inp/62.04).toFixed(2);
break;
amount = (inp*71.01).toFixed(2);
break;
amount = (inp/71.01).toFixed(2);
break;
document.getElementById("amount").value = amount;
</script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
<select id ="currency">
</select>
<br><br>
<input id ="value"/>
<br><br>
</div>
</body>
</html>
Looping Controls - CC
<html>
<head>
<style>
#header {
background-color: lightgrey;
</style>
</head>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<td style="width: 60%;">
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
<script>
function compute(){
var total=0;
for(i=0; i<res.length;i+=3){
total = total+(res[((i+3)-1)]*1);
}
</script>
</head>
<body onload="reLoad()">
<div>
</textarea>
</p>
</p>
</div>
</div>
</body>
</html>
Functions - CC
Number of days: -
Script.js: -
function calculate()
var cd = a;
while (cd<=b)
if(!((dow==6)||(dow===0)))
c++;
cd.setDate(cd.getDate()+1)
Index.html:-
<html>
<head>
<style>
#header {
background-color: lightgrey;
</style>
<script src="script.js"></script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
<h2>Number of days</h2>
<table>
<tr>
<tr>
</tr>
<tr>
</tr>
</table>
<div id="result"></div>
</body>
</html>
Frequency Calculation: -
Index.html: -
<html>
<head>
</script>
</head>
<body>
</textarea>
</p>
</div>
</div>
</body>
</html>
Script.js: -
function calculateFrequency()
text= text.toLowerCase();
arr.sort();
for(var i=0;i<arr.length;i++)
for(var j=0;j<arr.length;j++)
if(arr[i]== arr[j])
counter = counter+1;
}
}
obj[arr[i]] = counter;
temp = "";
for(var i in obj)
document.getElementById('result').innerHTML = temp;
Script.js: -
function getItemDetails() {
var i = 0;
for(item in items){
y = y + "<tr>";
y = y + "<td><input type='checkbox' id='check"+ i +"'></td>";
y = y + "</tr>";
i = i+1;
y = y + "</table>";
document.getElementById("test").innerHTML = y;
function compute(){
var cost = 0;
}
var lap = document.getElementById("text1").value;
function Item(itemName,price,availableQuantity)
this.itemName = itemName;
this.price = price;
this.availableQuantity = availableQuantity;
function createItem()
var element;
element=new Item("Computer","35000",5);
itemArray.push(element);
element=new Item("Laptop","45000",9);
itemArray.push(element);
element=new Item("Mobile","15000",15);
itemArray.push(element);
element=new Item("Television","25000",8);
itemArray.push(element);
element=new Item("Refrigerator","30000",6);
itemArray.push(element);
return itemArray;
}
Index.html: -
<html>
<style>
table, th, td {
</style>
<head>
</head>
<body onload="getItemDetails()">
</body>
</html>
User Details
function bindValues()
{
function validate()
var flagEmail = 0;
var flagName = 0;
var flagMobile = 0;
else {
nameWarning.innerHTML = "";
flagName = 1;
}
if(email==="" || email===" ")
else {
emailWarning.innerHTML = "";
flagEmail = 1;
else {
mobileWarning.innerHTML = "";
flagMobile = 1;
function User(name,address,mobileNumber,email) {
this.name = name;
this.address = address;
this.mobileNumber = mobileNumber;
this.email = email;
}
<html>
<head>
</head>
<body>
<h2>User Details</h2>
<table>
<tr>
<td>Name*</td>
</tr>
<tr>
<td>Address</td>
<td><textarea id="address"></textarea></td>
<td></td>
</tr>
<tr>
<td>Mobile Number*</td>
</tr>
<tr>
<td>E-mail Id*</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</body>
</html>
Index.html: -
<html>
<head>
<style>
td{
padding-bottom: .5em;
padding-top: .5em;
}
#table1{
padding-left: 300px;
padding-right: 100px;
#resultTable{
</style>
</head>
<body>
<tr>
<td>Name</td>
</tr>
<tr>
<td>ShipmentId</td>
<tr>
<td>Source</td>
</tr>
<tr><td>Destination</td>
<tr><td>Position</td>
<tr>
</td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
</table>
<tr>
<th>Name</th><th>ShipmentId</th><th>Source</th><th>Destination</th></tr>
<tr>
<td>Edward</td>
<td>56789543</td>
<td>Delhi</td>
<td>America</td>
</tr>
<tr>
<td>Aster</td>
<td>56789234</td>
<td>Norway</td>
<td>India</td>
</tr>
<tr>
<td>Charle</td>
<td>98789234</td>
<td>Japan</td>
<td>China</td>
</tr>
<tr>
<td>Vikrant</td>
<td>98695234</td>
<td>Australia</td>
<td>North America</td>
</tr>
</table>
</body>
</html>
Script.js: -
function insert()
var rname=document.getElementById("name").value;
var rsid=document.getElementById("id").value;
var rsource=document.getElementById("source").value;
var rdest=document.getElementById("destination").value;
var rpos=document.getElementById("position").value;
cell1.innerHTML = rname;
cell2.innerHTML = rsid;
cell3.innerHTML = rsource;
cell4.innerHTML = rdest;
document.getElementById("name").value="";
document.getElementById("id").value="";
document.getElementById("source").value="";
document.getElementById("destination").value="";
document.getElementById("position").value="";
}
AJAX - CC
Index.html: -
<html>
<head>
<style>
</style>
</head>
<body>
<center>
<form>
<h2>Asset Details</h2>
<div id="result">
</div>
</center>
</body>
</html>
Script.js:-
function search(){
var id = document.getElementById("input").value;
var idArr=[];
var nameArr=[];
var desArr=[];
var filteredContactArr=[];
xmlhttp.onreadystatechange = function() {
for(var i=0;i<len;i++)
idArr[idArr.length]=contactArr[i].id;
nameArr[nameArr.length]=contactArr[i].name;
desArr[desArr.length]=contactArr[i].des;
for(var i=0;i<idArr.length;i++)
if(id==str[0]||id==(str[0]+str[1])||id==(str[0]+str[1]+str[2]))
filteredContactArr[filteredContactArr.length]=idArr[i];
filteredContactArr[filteredContactArr.length]=nameArr[i];
filteredContactArr[filteredContactArr.length]=desArr[i];
if(filteredContactArr.length==0)
document.getElementById("result").innerHTML=txt1;
//document.getElementById("result").style.display="block";
}
else
for(var b=0;b<filteredContactArr.length;)
txt =
txt+"<tr><td>"+filteredContactArr[b]+"</td><td>"+filteredContactArr[b+1]+"</td><td>"+filteredContact
Arr[b+2]+"</td></tr>";
b=b+3;
txt=txt+"</table>";
document.getElementById("result").innerHTML=txt;
};
xmlhttp.send();
************************************************************************************
HTML - Print Welcome Message
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<html>
<head>
<style>
#header {
background-color: lightgrey;
td{
padding-top: .5em;
padding-bottom: .5em;
</style>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
<h3>About us :</h3>
<p>
</p>
</center>
</span>
</td>
<span>
<a href="#" id="signup">Sign up</a>
</span>
</td>
</tr>
</table>
</div>
</tr>
<tr>
<td colspan="2" align="center" > <button type="button" id="compute" name ="compute"
onclick=compute()>Compute</button></td>
</tr>
<tr>
<td colspan="2">
</tr>
</table>
<script>
function compute()
var val=document.getElementById("asset").value;
//alert(val);
var value1="";
array=val.split(",");
if((array[a]%10)==5)
value1=value1+array[a]+",";
</script>
</body>
</html>
<html>
<head>
<style>
#header {
background-color: lightgrey;
text-align: center;
</style>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
<script>
function multiply()
var Secval=parseInt(document.getElementById('cost').value);
</script>
</body>
</html>
<head>
<style>
#header {
border: 1px solid lightgrey;
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
</span>
</td>
</tr>
</table>
var total = 0;
for(var i = 0; i < outer_item.length; i++) {
total += Number(outer_item[i]);
}
</script>
</body>
</html>
Control Flow - LC
<style>
#header {
border: 1px solid lightgrey;
margin : -8px -8px 0;
background-color: lightgrey;
}
</style>
<script>
function compute(){
var weight = document.getElementById('weight').value;
var cost = 0;
if(document.getElementById('air').checked){
cost = 1*weight;
}
else if (document.getElementById('road').checked){
cost = 0.5*weight;
}
else{
cost=0.7*weight;
}
if(document.getElementById('premium').checked){
cost = cost -((cost*12)/100)
}
document.getElementById('result').innerHTML = "Dear Customer, your total
shipping cost is $"+cost;
}
</script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
</table>
</div>
<!-- fill code here -->
<h3 align= "center">Cargo Shipping Cost Calculation</h3>
<p align = "center">
weight(in kg):
<input type = "text" id="weight"/>
</p>
<p align = "center">
Transport Mode :
<input type = "radio" name= "mode" id="air"/>
<input type = "radio" name= "mode" id="road"/>
<input type = "radio" name= "mode" id="ship"/>
</p>
<p align = "center">
Premium Customer:
<input type = "checkbox" id="premium"/>
</p>
<p align = "center">
<input type = "button" id="calculate" onclick= compute() value= "Calculate"/>
</p>
<div id ="result" align = "center">
</div>
</body>
</html>
2. Password Validation
<!DOCTYPE html>
<html>
<head>
<style>
#header {
border: 1px solid lightgrey;
margin : -8px -8px 0;
background-color: lightgrey;
}
</style>
<script type="text/javascript">
function compute(){
var pass = document.getElementById('password').value;
var repass = document.getElementById('repassword').value;
if (pass==repass){
var res = "Registration is Successful<br><br>"+"<h2> Welcome to DATAX
Shipping Company</h2>"
document.getElementById('message').innerHTML = res;
document.getElementById('message').style="color:green";
}
else{
document.getElementById('errorMessage').innerHTML = "Registration failed
<br> Password and re-enter password doesn't match";
}
}
</script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
<a href="#" id="login" style="padding-left:30px">Log in</a>
</span>
</td>
</tr>
</table>
</div>
<!-- fill code here -->
<form>
<div align= "center" id ="message">
<br><br>
<label for="password">Password:<label/>
<input type = "password" id ="password"/>
<br><br>
</form>
</body>
</html>
Looping Controls - LC
1.Number Sequence
<!DOCTYPE html>
<html>
<head>
<style>
#header {
border: 1px solid lightgrey;
<body>
<script type="text/javascript">
function findNum()
{
var addr = document.getElementById("address").value;
var reg = /\d+/g
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg" width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
</html>
background-color: lightgrey;
}
</style>
</head>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
<img align="left" src="logo.jpeg"
width="120px" height="120px">
</span>
</td>
<td style="width: 60%;">
<span>
<center>
<h1>DATAX Shipping Company</h1>
</center>
</span>
</td>
<td style="width: 40%; padding-bottom: 7%;padding-
left:5%;">
<span>
<a href="#" id="signup">Sign up</a>
<a href="#" id="login" style="padding-
left:30px">Log in</a>
</span>
</td>
</tr>
</table>
</div>
</div>
<div id="warning" />Your message should not exceed more than 100 words </div>
<script>
function details()
{
document.getElementById("success").style.visibility = "visible";
}
</script>
</head>
<!-- Your code here -->
</body>
</html>
Functions – LC
1. Checking Number
<html>
<head>
<style>
#header {
background-color: lightgrey;
</style>
<script type="text/javascript">
function check() {
//'use strict';
//console.log(isNaN(inputValue));
if (isNaN(inputValue)) {
document.getElementById("result").style.color = 'red';
}else
document.getElementById("result").style.color = 'green'
document.getElementById("result").innerHTML = "The Given input is a number";
</script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
<h2>Checking Number</h2>
<div id="result"></div>
</body>
</html>
2. Date Validation
<!DOCTYPE html>
<html>
<head>
<style>
#header {
background-color: lightgrey;
#textArea{
width: 200px;
height: 150px;
</style>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
</head>
<body>
</p>
</div>
</div>
</body>
script.js
function dateValidate()
document.getElementById('result').style = "color:green"
else
document.getElementById('result').style = "color:red"
<head>
<style>
#header {
background-color: lightgrey;
</style>
<script type="text/javascript">
function validate()
if(inp.match(letters))
document.getElementById('result').style = "color:green"
else
document.getElementById('result').style = "color:red"
</script>
</head>
<body>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
5.Vowels Count
<html>
<head>
<style>
#header {
background-color: lightgrey;
</style>
<div id="header">
<table style="width:100%">
<tr style="width:100%">
<td style="width:20%">
<span>
</span>
</td>
<span>
<center>
</center>
</span>
</td>
<span>
</span>
</td>
</tr>
</table>
</div>
</head>
<body>
Number of vowels
<div id="result"></div>
</body>
</html>
scrtipt.js
function getVowels()
var inputString=document.getElementById("string").value;
var vowelC=0;
// var total_findVowles="";
for(var i=0;i<inputString.length;i++)
if (inputString.charAt(i).match(/[a-zA-Z]/)!=null)
if (inputString.charAt(i).match(/[aeiouAEIOU]/))
{ vowelC++;}
1.Policy Details
<html>
<head>
<body>
</p>
</div>
</div>
</body>
</html>
Script.js
function addPolicy()
policy[len]=num.substring(0,4)
function displayPolicy()
2.Address Details
<html>
<head>
</head>
<body>
<center>
<br><br>
</center>
</body>
</html>
script.js
if(addr.value.replace(/^\s+|\s+$/gm,'') !=="") {
address.push(addr.value);
addr.value = "";
function displayAddress(){
display[i] = address[i];
result.innerHTML += addrno[i]+"<br>"+display[i]+"<br>";
display = [];
addrno = [];
address = [];
1.Customer Details
<html>
<head>
<script src="script.js" type="text/javascript"> </script>
</head>
<body>
Customer Name
Address
</textarea><br><br>
Phone Number
</p>
</div>
</div>
</body>
</html>
script.js
function display(){
document.getElementById('result').innerHTML = cus.getInfo();
}
function Customer(name,adres,num)
this.name = name;
this.adres= adres;
this.num= num;
Customer.prototype.getInfo= function(){
return temp;
};
3.Asset Summary
<html>
<head>
<style>
table, th,td {
ul{
width:5%
}
li{
width:20%;
display:block;
li{
list-style:none;
clear:both;
li label{
float:left;
li span{
float:center;
li input{
float:right;
</style>
</head>
<body>
<center>
<h2>Asset Details</h2>
<ui>
<li>
<label>Asset ID</label>
<span>:</span>
<br/>
<br/>
</li>
<li>
<label>Asset Type</label>
<span>:</span>
<br/>
<br/>
</li>
<li>
<label>Supplier Name</label>
<span>:</span>
<br/>
<br/>
</li>
<li>
<label>Manufacturer</label>
<span>:</span>
<br/>
<br/>
</li>
<li>
<div id="result">
<h3></h3>
<table id="tab">
</table>
</div>
</ui>
</center>
</body>
script.js
var i=0;
var assetArray=[];
var assetquantity={};
function addAsset() {
assetArray[i]=new Asset(assetId,type,supplier,manufacturer);
i++;
console.log(elements[ii].type);
if (elements[ii].type == "text") {
elements[ii].value = "";
function displayAsset() {
for(var j=0;j<assetArray.length;j++){
if(assetquantity[assetArray[j].type]){
assetquantity[assetArray[j].type]++;
} else{
assetquantity[assetArray[j].type]=1;
var k=1;
while (result.hasChildNodes()) {
result.removeChild(result.lastChild);
document.getElementById('result').getElementsByTagName('h3')[0].innerHTML="Asset Details";
var ir = result.insertRow(0);
ir.insertCell(0).outerHTML="<th>Asset Type</th>"
ir.insertCell(1).outerHTML="<th>Quantity</th>"
cell2.innerHTML=assetquantity[assetname];
k++;
i=0;
assetArray=[];
assetquantity={};
function Asset(assetId,type,supplier,manufacturer){
this.assetId=assetId;
this.type=type;
this.supplier=supplier;
this.manufacturer=manufacturer;
1.User Details
<html>
<head>
</head>
<body>
<h2>User Details</h2>
<table>
<tr>
<td>Name*</td>
</tr>
<tr>
<td>Address</td>
<td><textarea id="address"></textarea></td>
<td></td>
</tr>
<tr>
<td>Mobile Number*</td>
</tr>
<tr>
<td>E-mail Id*</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</body>
</html>
script.js
function bindValues()
function validate()
var flagEmail = 0;
var flagName = 0;
var flagMobile = 0;
else {
nameWarning.innerHTML = "";
flagName = 1;
else {
emailWarning.innerHTML = "";
flagEmail = 1;
else {
mobileWarning.innerHTML = "";
flagMobile = 1;
function User(name,address,mobileNumber,email) {
this.name = name;
this.address = address;
this.mobileNumber = mobileNumber;
this.email = email;
<head>
<style>
#Shipment{
background-color: #e6e6e6;
padding-top: 15px;
padding-left: 150px;
padding-right: 150px;
border-style: solid;
td{
padding-bottom: .5em;
padding-top: .5em;
}
h2{
text-align: center;
div{
color: red;
#result{
color:green;
#submit{
display: block;
margin: auto;
</style>
</head>
<body onload="generateShippingDate()">
<tr><td colspan="3"><hr></td></tr>
<option value="India">India</option>
<option value="Bahrain">Bahrain</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="Algeria">America</option>
<option value="Andorra">Andorra</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Canada">Canada</option>
<option value="Afghanistan">Afghanistan</option>
</select></td>
<td><div id="errorCountry"></div></td>
</tr>
<option value="Tamil">Tamil</option>
<option value="English">English</option>
<option value="Spanish">Spanish</option>
<option value="Greek">Greek</option>
<option value="French">French</option>
<option value="Russian">Russian</option>
<option value="Hindi">Hindi</option>
<option value="Arabic">Arabic</option>
<option value="German">German</option>
<option value="Spanish">Spanish</option>
<option value="Farsi">Farsi</option>
</select></td>
<td><div id="errorSuburb"></div></td>
</tr>
<td><div id="errorMobile"></div></td>
</tr>
<tr><td colspan="3"><hr></td></tr>
<option value="India">India</option>
<option value="Bahrain">Bahrain</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="America">America</option>
<option value="Andorra">Andorra</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Canada">Canada</option>
<option value="Afghanistan">Afghanistan</option>
</select></td>
<td><div id="errortoCountry"></div></td>
</tr>
<option value="Tamil">Tamil</option>
<option value="English">English</option>
<option value="Spanish">Spanish</option>
<option value="Greek,">Greek,</option>
<option value="French">French</option>
<option value="Russian">Russian</option>
<option value="Hindi">Hindi</option>
<option value="Arabic">Arabic</option>
<option value="German">German</option>
<option value="Spanish">Spanish,</option>
<option value="Farsi">Farsi</option>
</select></td>
<td><div id="errortoMobile"></div></td>
</tr>
<tr><td colspan="3"><hr></td></tr>
</table>
</body>
</html>
script.js
function generateShippingDate() {
var monArray;
if (year % 4 === 0) {
leap = true;
else {
leap = false;
else {
leap = true;
else {
leap = false;
monArray = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
else {
monArray = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
dateArray[dateArray.length] = dt;
day = day + 1;
else {
dateArray[dateArray.length] = dt;
day = day + 1;
month = 0;
year = year + 1;
day = 1;
dateArray[dateArray.length] = dt;
day = day + 1;
shipselect.remove(1);
var option = document.createElement("option");
option.text = "Today";
option.value = "Today";
shipselect.add(option);
option.text = dateArray[i];
option.value = dateArray[i];
shipselect.add(option);
var validArray = [false, false, false, false, false, false, false, false, false, false, false, false, false];
function fieldValidate() {
validArray[0] = false;
else {
validArray[0] = true;
document.getElementById("errorCountry").innerHTML = '';
validArray[1] = false;
else {
validArray[1] = true;
document.getElementById("errorLanguage").innerHTML = '';
if (postalCode === "" || postalCode === " " || postalCode === null) {
validArray[2] = false;
else {
validArray[2] = true;
document.getElementById("errorPostal").innerHTML = '';
if (city === "" || city === " " || city === null) {
validArray[3] = false;
else {
validArray[3] = true;
document.getElementById("errorCity").innerHTML = '';
if (suburb === "" || suburb === " " || suburb === null) {
validArray[4] = false;
else {
validArray[4] = true;
document.getElementById("errorSuburb").innerHTML = '';
}
if (mobile === "" || mobile === " " || mobile === null) {
validArray[5] = false;
else {
validArray[5] = true;
document.getElementById("errorMobile").innerHTML = '';
validArray[6] = false;
else {
validArray[6] = true;
document.getElementById("errortoCountry").innerHTML = '';
validArray[7] = false;
else {
validArray[7] = true;
document.getElementById("errortoLanguage").innerHTML = '';
validArray[8] = false;
else {
validArray[8] = true;
document.getElementById("errortoPostal").innerHTML = '';
if (toCity === "" || toCity === " " || toCity === null) {
validArray[9] = true;
else {
validArray[9] = true;
document.getElementById("errortoCity").innerHTML = '';
if (toSuburb === "" || toSuburb === " " || toSuburb === null) {
validArray[10] = false;
else {
validArray[10] = true;
document.getElementById("errortoSuburb").innerHTML = '';
if (toMobile === "" || toMobile === " " || toMobile === null) {
validArray[11] = false;
document.getElementById("errortoMobile").innerHTML = 'Please enter the mobile number';
else {
validArray[11] = true;
document.getElementById("errortoMobile").innerHTML = '';
//alert(shipping);
validArray[12] = false;
else {
validArray[12] = true;
document.getElementById("errorShip").innerHTML = '';
function registerShipping() {
fieldValidate();
result = validArray[i];
break;
else {
document.getElementById("result").innerHTML = "";
<html>
<head>
<style>
#xx {
width: 700px;
height: 690px;
.button {
background-color: red;
border: none;
margin-top: 210px;
color: white;
padding: 10px 20px;
span {
color: red;
#hour, option {
width: 45px;
#minute, option {
width: 45px;
#ampm, option {
width: 55px;
#hour1, option {
width: 45px;
#minute1, option {
width: 45px;
#ampm1, option {
width: 55px;
}
#locationTypeError, #locationError {
color: red;
#zipError, #phoneError {
color: red;
.button button3 {
color: black;
</style>
</head>
<body onload="preloadDetails()">
<center>
<h2>Schedule a Pickup</h2>
<tr>
<td>Schedule Pickup</td>
</tr>
<tr>
<td>Pickup</td>
</tr>
<tr>
<td>Contact<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="contactError"></div></td>
</tr>
<tr>
<td>Company<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="companyError"></div></td>
</tr>
<tr>
<td>Address 1<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="address1Error"></div></td>
</tr>
<tr>
<td>Address 2</td>
<td></td>
</tr>
<tr>
<tr>
<td>Address 3</td>
<td></td>
</tr>
<tr>
</tr>
<tr>
<td>City<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="cityError"></div></td>
</tr>
<tr>
<td>State/Province</td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Zip/Postal Code<span>*</span></td>
<td></td>
</tr>
<tr>
<td><input type="text" id="zipcode" onchange="fieldValidate()"></td>
<td><div id="zipError"></div></td>
</tr>
<tr>
<td>Country</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Phone<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="phoneError"></div></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><div id="pieceError"></div></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><div id="weightError"></div></td>
</tr>
</table>
<div style="margin-top:47px"></div>
<tr>
<td>Location Type<span>*</span></td>
</tr>
<tr>
<td>
<option value="Select">Select</option>
<option value="Business">Business</option>
<option value="Personal">Personal</option>
<option value="Economic">Economic</option>
</select>
</td>
<td><div id="locationTypeError"></div></td>
</tr>
<tr>
<td>Location of shipment(s)<span>*</span></td>
<td></td>
</tr>
<tr>
<td><div id="locationError"></div></td>
</tr>
<tr>
<td>Special Instructions</td>
</tr>
<tr>
<td><textarea id="instruction"></textarea></td>
</tr>
<tr>
<td>Pickup Date</td>
</tr>
<tr>
<td>
<option value=1>TODAY</option>
<option value=2>TOMORROW</option>
</select>
</td>
</tr>
<tr>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>Your pickup must be ready by</td>
<td><div id="pickupready"></div></td>
</tr>
<tr>
</tr>
<tr>
<td>
<option value="06">06</option>
</select>
<option value="30">30</option>
</select>
<option value="PM">PM</option>
</select>
</td>
</tr>
</table>
</div>
</center>
</body>
</html>
script.js
function preloadDetails() {
if (i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) {
option.text = '0' + i;
option.value = '0' + i;
else {
option.text = i;
option.value = i;
hour.add(option);
if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) {
option.text = '0' + i;
option.value = '0' + i;
else {
option.text = i;
option.value = i;
minute.add(option);
}
option.text = "AM";
option.value = "AM";
format.add(option);
option = document.createElement("option");
option.text = "PM";
option.value = "PM";
format.add(option);
function fieldValidate() {
hasError = true;
} else {
document.getElementById("contactError").innerHTML = "";
hasError = true;
} else {
document.getElementById("companyError").innerHTML = "";
hasError = true;
} else {
document.getElementById("address1Error").innerHTML = "";
hasError = true;
} else {
document.getElementById("cityError").innerHTML = "";
hasError = true;
} else {
document.getElementById("zipError").innerHTML = "";
hasError = true;
} else {
document.getElementById("phoneError").innerHTML = "";
}
hasError = true;
} else {
document.getElementById("pieceError").innerHTML = "";
hasError = true;
} else {
document.getElementById("weightError").innerHTML = "";
if (locationType == "Select") {
hasError = true;
} else {
document.getElementById("locationTypeError").innerHTML = "";
hasError = true;
} else {
document.getElementById("locationError").innerHTML = "";
}
var hour = document.getElementById("hour").value;
if (format == "PM") {
if (hour == 24) {
hour = '12';
if (hour == 12) {
hour = '00';
document.getElementById("pickupready").innerHTML = timeString;
return hasError;
function submitSchedule() {
if (!fieldValidate()) {
document.getElementById("contact").value = "";
document.getElementById("company").value = "";
document.getElementById("address1").value = "";
document.getElementById("address2").value = "";
document.getElementById("address3").value = "";
document.getElementById("city").value = "";
document.getElementById("state").value = "";
document.getElementById("zipcode").value = "";
document.getElementById("country").value = "";
document.getElementById("phone").value = "";
document.getElementById("piece").value = "";
document.getElementById("weight").value = "";
document.getElementById("locationType").value = "Select";
document.getElementById("location").value = "";
document.getElementById("instruction").value = "";
document.getElementById("date").value = "1";
document.getElementById("hour").value = "01";
document.getElementById("minute").value = "00";
document.getElementById("format").value = "AM";
AJAX - LC
<head>
<style>
#result table
border-collapse: collapse;
position: relative;
</style>
<!--script src="data.json"></script-->
</head>
<body onload="loadDoc()">
<center>
<h2>Shipment Details</h2>
<div id='result'>
<table id ='myTable'>
<tr>
<th>Shipment Number</th>
<th>Source</th>
<th>Destination</th>
<th>Start Date</th>
<th>Delivered Date</th>
<th>Weight</th>
</tr>
</table>
</div>
</center>
</body>
</html>
script.js
function loadDoc(){
xmlhttp.onreadystatechange = function() {
for(var i=0;i<len;i++)
cell1.innerHTML = bookArr[i].Booking_ID;
cell2.innerHTML = bookArr[i].Arrival_Port;
cell3.innerHTML = bookArr[i].Departure_Port;
cell4.innerHTML = bookArr[i].Arrival_Date;
cell5.innerHTML = bookArr[i].Departure_Date;
cell6.innerHTML = bookArr[i].Weight;
tableLength=tableLength+1;
};
xmlhttp.open("GET", "data.json", true);
xmlhttp.send();
data.json
"book": [
"Booking_ID" : "12789651",
"Arrival_Port" : "Chennai",
"Departure_Port" : "Coimbatore",
},
"Booking_ID" : "98781121",
"Arrival_Port" : "Mumbai",
"Departure_Port" : "Delhi",
},
"Booking_ID" : "17896500",
"Arrival_Port" : "Coimbatore",
"Departure_Port" : "Salem",
},
"Booking_ID" : "34290111",
"Arrival_Port" : "Bangalore",
"Departure_Port" : "Cochin",
<html>
<head>
<style>
</style>
</head>
<body>
<center>
<h2>Shipment Details</h2>
<div id='test'>
<table cellpadding="25">
<tr align="center">
</tr>
</div>
<br>
<br>
</table>
<div id='result'>
</div>
</center>
</body>
</html>
script.js
function search(){
xmlhttp.onreadystatechange = function() {
myFunction(this);
};
xmlhttp.send();
function myFunction(xml) {
xmlDoc = xml.responseXML;
a = xmlDoc.getElementsByTagName("name");
alen = a.length;
for(j=0;j<alen;j++)
if(a[j].childNodes[0].nodeValue==cName)
x = xmlDoc.getElementsByTagName("shipment")[j];
xlen = x.childNodes.length;
y = x.firstChild;
if (y.nodeType == 1)
{
resArray[resArray.length] = y.childNodes[0].nodeValue;
y = y.nextSibling;
if(resArray.length===0)
document.getElementById("result").innerHTML=txt1;
else
for(var b=0;b<resArray.length;)
txt =
txt+'<tr><td>'+resArray[b+1]+'</td><td>'+resArray[b]+'</td><td>'+resArray[b+2]+'</td><td>'+resArray[
b+3]+'</td><td>'+resArray[b+4]+'</td><td>'+resArray[b+5]+'</td></tr>';
b=b+6;
txt=txt+'</table>';
document.getElementById("result").innerHTML=txt;
}
ShipmentDetails.xml
<catalog>
<shipment>
<name>Charles</name>
<shipmentId>46789056</shipmentId>
<source>India</source>
<destination>North America</destination>
<startDate>05/06/2017</startDate>
<deliveredDate>26/06/2017</deliveredDate>
</shipment>
<shipment>
<name>Charles</name>
<shipmentId>46789696</shipmentId>
<source>Delhi</source>
<destination>Greece</destination>
<startDate>09/06/2017</startDate>
<deliveredDate>30/06/2017</deliveredDate>
</shipment>
<shipment>
<name>Edward</name>
<shipmentId>98767894</shipmentId>
<source>Pune</source>
<destination>Italy</destination>
<startDate>25/06/2017</startDate>
<deliveredDate>05/07/2017</deliveredDate>
</shipment>
<shipment>
<name>Aster</name>
<shipmentId>88950075</shipmentId>
<source>Italy</source>
<destination>California</destination>
<startDate>25/08/2017</startDate>
<deliveredDate>06/09/2017</deliveredDate>
</shipment>
<shipment>
<name>Aster</name>
<shipmentId>88950075</shipmentId>
<source>Japan</source>
<destination>China</destination>
<startDate>25/07/2017</startDate>
<deliveredDate>29/07/2017</deliveredDate>
</shipment>
<shipment>
<name>Vikrant</name>
<shipmentId>98765240</shipmentId>
<source>New york</source>
<destination>Chennai</destination>
<startDate>03/07/2017</startDate>
<deliveredDate>10/07/2017</deliveredDate>
</shipment>
</catalog>
JavaScript Multiple Choice Questions and Answers- Sheet 1
1. Why so JavaScript and Java have similar name?
A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above
Ans: B
2. When a user views a page containing a JavaScript program, which machine actually executes the
script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above
Ans: A
6. _____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-
clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native
Ans: A
11. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE>
Ans: A
13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above
Ans: A
17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above
Ans: C
19. Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above
Ans: A
22. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the
paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
Ans: B
23. JavaScript entities start with _______ and end with _________.
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
Ans: D
28. ______method evaluates a string of JavaScript code in the context of the specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
Ans: A
29. Which of the following event fires when the form element loses the focus: <button>, <input>,
<label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
Ans: B
32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
Ans: B
35. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
Ans: D
36. To set up the window to capture all Click events, we use which of the following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
Ans: A
39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
Ans: C
40. In JavaScript, _________ is an object of the target language data type that encloses an object of
the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
Ans: A
41. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
42. _______ class provides an interface for invoking JavaScript methods and examining JavaScript
properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
Ans: B
43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: A
44. A ________ object is a reference to one of the classes in a Java package, such as
netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
Ans: B
45. The JavaScript exception is available to the Java code as an instance of __________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
Ans: B
46. To automatically open the console when a JavaScript error occurs which of the following is added
to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
Ans: D
47. To open a dialog box each time an error occurs, which of the following is added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
Ans: A
49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
Ans: C
Output------?
A. 44
B. 8
C. 4
D. Error output
Ans: A
53. <script>
document.write(navigator.appCodeName);
</script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
Ans: A
Output------?
a) 44
b) 8
c) 4
d) Error output
4) <script>
document.write(navigator.appCodeName);
< /script>
a) get code name of the browser of a visitor
b) set code name of the browser of a visitor
c) None of the above
8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
20) parseFloat(9+10)=?
a) 19
b) 910
c) None
</script>
a) hello
b) bye
c) Error in string handling
d) None of the above
26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
27) How do you create a new object in JavaScript?
a) var obj = {};
b) var obj = Object();
c) var obj=new {};
d) None of the above
29) If x=103 & y=9 then x%=y , what is the value of x after executing x%=y?
a) 4
b) 3
c) 2
d) 5
31) Choose the four symbol pairs that represent RegExp properties lastMatch, lastParent,
leftContext, and rightContext, respectively:
a) $&, $+, $`, $'
b) $+, $&, $', $`
c) $&, $~, $`, $'
d) $+, $&, $`, $'
32) Which of the following properties hold the values of the pixels of the length of the width
and height of the viewer's screen resolution?
a) screen.width and screen.height
b) Resolution.width and Resolution.height
c) screen.pixels.width and screen.pixels.height
d) ViewerScreen.width and ViewerScreen.height
33) ParseInt(“15”,10)=?
a) 15
b) 10
c) 151
d) 150
</script>
a) in in In
b) in in in
c) in in null
d) in null null
a) first
b) undefined
c) First
d) Error
51) How to speicfy the color of the hypertext links with JavaScript ?
a) document.linkColor="#00FF00";
b) document.LColor="#00FF00";
c) document.LinkC="#00FF00";
d) document.hyperTextLink="#00FF00":
59) In Javascript, Which of the following method is used to find out the character at a
position in a string?
a) charAt()
b) CharacterAt()
c) CharPos()
d) characAt()
</script>
a) Po
b) yP
c) oi
d) P
64) What are the following looping structures are available in javascripts?
a) for,forecach
b) foreach,whileloop
c) do-while loop,foreach
d) for , while loop
67) In javascript, RegExp Object Method test() is used to search a string and returns
_________
a) true or false
b) found value
c) index
d) None of the above
68) What property would you use to redirect a visitor to another page?
a) document.URL
b) window.location.href
c) .document.location.href
d) link.href
Question:
In javascript, which of the above statement can used for string declaration ?
</script>
a) in in In
b) in in in
c) in in null
d) in null null
73) -------------- method is used to remove focus from the specified object.
a) blur()
b) focus()
c) None
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
75)eval((20*4)=?
a) Nan
b) 204
c) 24
d) 80
76)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("TECHNOLOGIES","i");
document.write(qpt.match(pattern));
}
</script>
a) null
b) Technologies
c) TECHNOLOGIES
d) Error
If an exception is thrown
Can appear in both the <head> block and within the <block>
The loop type always runs the enclosed code at least once
1. The triple equal sign === checks for equal value and equal type
{javascript Array: Shift() Method. The shift() method is like the pop() method, only it works at
the beginning of the array. The shift() method pulls the first element off of the given array and
returns it. This alters the array on which the method was called}
while
do-while
For
var el = document.getElementById("awesome");
10. How will you select elements in a page having class
"super" using JavaScript?
For this we will use the document.getElementsByClassName() method.
In the following example we are selecting all the elements in the page having class "super".
2. which of the following is false about variable name : Variable name is not case sensitive
4. Var mood = Joy + Happiness : Joy is added to Happiness and stored in the variable Mood
8. --------- class is used in javascript for manipulating date and time?: Date
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
</script>
a) in in In
b) in in in
c) in in null
d) in null null
71) <script language="javascript">
function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat
Question:
In javascript, which of the above statement can used for string declaration ?
</script>
a) Po
b) yP
c) oi
d) P
a) first
b) undefined
c) First
d) Error
</script>
a) in in In
b) in in in
c) in in null
d) in null null
26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>
Output------?
a) 44
b) 8
c) 4
d) Error output
74) parseFloat(“FF2”)=?
a) 152
b) FF2
c) NaN
d) None
Show Answer
</script>
a) in in In
b) in in in
c) in in null
d) in null null
71) <script language="javascript">
function x()
{
var s = "Eat to live, but do not live to eat";
var pattern = new RegExp("eat$");
document.write(pattern.exec(s));
}
</script>
a) Eat
b) eat
c) undefined
d) Eat eat
Question:
In javascript, which of the above statement can used for string declaration ?
</script>
a) Po
b) yP
c) oi
d) P
a) first
b) undefined
c) First
d) Error
</script>
a) in in In
b) in in in
c) in in null
d) in null null
26)<script language="javascript">
function x()
{
var qpt = "QualityPointTechnologies";
var pattern = new RegExp("POIiNT","i");
document.write(qpt.match(pattern));
}
</script>
a) Error
b) POIiNT
c) Point
d) null
9) <script language="javascript">
var qpt="QUALITY POINT TECHNOLOGIES";
alert(qpt.charAt(qpt.length-1));
</script>
a) P
b) E
c) S
d) Error
8) <script language="javascript">
function x()
{
var s= "Good 100%";
var pattern = /\D/g;
var output= s.match(pattern);
document.write(output);
}
</script>
a) Good %
b) 1,0,0
c) G,o,o,d,%
d) Error
1) <script type="text/javascript">
x=4+"4";
document.write(x);
</script>
Output------?
a) 44
b) 8
c) 4
d) Error output