Javascript

91
1 Code timeout=setTimeout("updateTimeStamp();",5000); 1 – 10 Which one of the following is true of the code segment above? It causes setTimeout() to initialize the date and time library. It fires an event to invoke updateTimeStamp() every five seconds. It creates a Time object that ticks once every 0.5 seconds. It fires an event to invoke updateTimeStamp() in five seconds. It adds an onTimeOut event handler to the document. Ans: It fires an event to invoke updateTimeStamp() in five seconds. Code setTimeout("cycle()",3 * 3000); How often is function cycle() called in the above code? 3 milliseconds 3.003 seconds 3000 milliseconds 9 seconds 9000 seconds Ans: 9 seconds Date: 4/26/2009 Time: 10:13:9 currentDate = new Date() with (currentDate) { document.write("Date: "+getMonth() + "/"+getDate()+"/"+getYear()+"<BR>") document.write("Time: "+getHours() + ":"+getMinutes()+":"+getSeconds()) } What is the output of the code above in the user's browser? (Assume user time is Thursday July 9, 2003, and the current time is 3:30:33 P.M. EST) Date: July/9/2003 Time: 3:30:33 Date: July/9/03 Time: 15:30:33 Date: 6/9/2003 Time: 15:30:33 Date: 7/9th/2003 Time: 3:30:33

Transcript of Javascript

Page 1: Javascript

1  

Code timeout=setTimeout("updateTimeStamp();",5000); 1 – 10

Which one of the following is true of the code segment above?

It causes setTimeout() to initialize the date and time library.

It fires an event to invoke updateTimeStamp() every five seconds.

It creates a Time object that ticks once every 0.5 seconds.

It fires an event to invoke updateTimeStamp() in five seconds.

It adds an onTimeOut event handler to the document.

Ans: It fires an event to invoke updateTimeStamp() in five seconds. 

 

Code setTimeout("cycle()",3 * 3000);

How often is function cycle() called in the above code?

3 milliseconds

3.003 seconds

3000 milliseconds

9 seconds

9000 seconds Ans: 9 seconds

 

Date: 4/26/2009 Time: 10:13:9 

 

 

currentDate = new Date() with (currentDate) { document.write("Date: "+getMonth() + "/"+getDate()+"/"+getYear()+"<BR>") document.write("Time: "+getHours() + ":"+getMinutes()+":"+getSeconds()) }

What is the output of the code above in the user's browser? (Assume user time is Thursday July 9, 2003, and the current time is 3:30:33 P.M. EST)

Date: July/9/2003 Time: 3:30:33

Date: July/9/03 Time: 15:30:33

Date: 6/9/2003 Time: 15:30:33

Date: 7/9th/2003 Time: 3:30:33

Page 2: Javascript

2  

Date: July/9th/2003 Time: 15:30:33

ANS: Date: 6/9/2003 Time: 15:30:33 

 

Which one of the following is true of the "Math" object?

It must be instantiated with Math(base) before any methods are used.

It provides methods and properties for various arithmetic operations.

It holds the base (10, 16, e, etc.) used in mathematical operations.

It holds string properties containing all arithmetic symbols.

It performs common vector-based drawing functions.

ANS: It provides methods and properties for various arithmetic operations.

What code asks if the user wants a greeting and, if so, displays "wel.gif" and writes "Welcome!" in the document window?

if (confirmed("OK to welcome?")) { alert.write(<IMG SRC="wel.gif">); alert.write(<BR><H1>Welcome!</H1>); }

if (confirmed("OK to welcome?")) { alert('<IMG SRC="welcome.gif">'); alert("<BR><H1>Welcome!</H1>"); }

if (confirm("OK to welcome?")) { document.write('<IMG SRC="wel.gif">'); document.write("<BR><H1>Welcome!</H1>"); }

if (confirm("OK to welcome?")) { document.write(<IMG SRC="wel.gif">); document.write(<BR><H1>Welcome!</H1>); }

if (confirm("OK to welcome?")) { document.write(<IMG SRC="wel.gif">); alert(<BR><H1>Welcome!</H1>); }

Ans : Option 3 if (confirm("OK to welcome?")) { document.write('<IMG SRC="wel.gif">'); document.write("<BR><H1>Welcome!</H1>"); }

Sample Code document.TestForm.TestSelect.options[1].selected = true;

What does the above code do?

It selects the first option in the TestForm on the TestSelect.

It deselects the first option in the TestSelect on the TestForm.

It deselects the second option in the TestSelect on the TestForm.

It selects the second option in the TestSelect on the TestForm.

It selects the first option in the TestSelect on the TestForm.

Page 3: Javascript

3  

Ans: It selects the second option in the TestSelect on the TestForm.

 

How do you change the document in the second frame to "test.html"?

top.frames[2].url = "test.html";

self.frames[1].url = "test.html";

self.frames[2].location.href = "test.html";

self.frames[1].href = "test.html";

self.frames[1].location.href = "test.html";

ANS: self.frames[1].location.href = "test.html"; 

 

The event method "setTimeout(code, time)" is a method belonging to which one of the following objects?

document

location

window

form

It does not belong to any object.

ANS: window 

 

 

 

Which one of the following statements is true?

Global variables must be used first in order to let the browser know to initialize it.

Global variables must be declared in an outside file.

Global variables are properties of a global object.

Global variables are always constants.

Global variables are inaccessible from more than one window. ANS: Global variables are properties of a global object.

Page 4: Javascript

4  

Which one of the following methods may need privileges?

escape(s)

document.clear()

form.submit()

navigator.javaEnabled()

self.close()

ANS: navigator.javaEnabled()

if (navigator.javaEnabled()) { function1() } else function2() .... a preference with the preference method requires the UniversalPreferencesRead privilege. ... 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- var x = confirm('Is it OK?'); // --> </SCRIPT>

What does x contain if the user presses "OK" on the confirm dialog above?

'OK'

true

1

A reference to the confirm dialog

'Is it OK?'

ANS: true 

 

 

 

 

What does window.length return?

The length in pixels

The number of open windows

The length as a percentage of screen size

The number of open browser windows

Page 5: Javascript

5  

The number of frames in the window

ANS: The number of frames in the window  

 

Sample Code var i = 0, j = 0; for ( ; i < 10; i++) j += ++i;

After the above code segment is run, what will be the values of 'i' and 'j'?

i = 12, j = 36

i = 11, j = 36

i = 10, j = 36

i = 11, j = 25

i = 10, j = 25

ANS: i = 10, j = 25

 

 

If a window contains only two sibling frames, which one of the following is equivalent to "parent" within one of those frames?

document

frames

top

window

self

ANS: top 

 

 

 

Code var total=0; for(var j=0;j<10;j++) { for(var i=0;i<3;i++) { if(j > 3) break; total++; } }

What is the value of "total" after execution of the code above?

Page 6: Javascript

6  

0

6

9

12

30 ANS: 12

 

 

Sample Code var win = window.open("", "newWindow", "height=200,width=200");

Referring to the above, in Netscape, which one of the following code segments centers the window "win" on the screen?

win.moveBy((win.screen.height - win.outerHeight) / 2, (win.screen.width - win.outerWidth) / 2);

win.moveBy((win.height - win.outerHeight) / 2, (win.width - win.outerWidth) / 2);

win.moveTo((win.height - win.outerHeight) / 2, (win.width - win.outerWidth) / 2);

win.center();

win.moveTo((win.screen.width - win.outerWidth) / 2, (win.screen.height - win.outerHeight) / 2);

ANS : win.moveTo((win.screen.width - win.outerWidth) / 2,

(win.screen.height - win.outerHeight) / 2);  

 

Which one of the following is NOT a javascript data type?

Floating-point

String

Integers

Boolean

Date

Ans : Floating‐point  

Sample Code var today; var tmpstr; today = Date();

Referring to the above, what method is automatically called if the following line were executed? Tmpstr = "Today = "+today;

toString()

display()

Page 7: Javascript

7  

show()

append()

No method is automatically called.

Ans : No method is automatically called/append

(doubt for this answer---Pooja) 

 

 

How is the error console opened from the browser's URL line in Netscape?

'javascript:debug'

'open javascript'

'javascript:open'

'javascript:error'

'javascript:'

Ans : 'javascript:'  

 

Sample Code var index; for (index = 0; index < testArray.length; index++); document.writeln(index);

Which one of the following code segments produces the same results as the code segment above?

document.writeln(index = testArray.elements);

for (index = 1; index <= testArray.length; index++); document.writeln(index);

document.writeln(index = testArray.getElements());

document.writeln(index = getLength(testArray));

document.writeln(index = testArray.length);

ANS: document.writeln(index = testArray.length); 

 

The form object has which event handler or handlers?

onChange, onSubmit

onSubmit, onReset

onLoad, onUnload

OnReset, onFocus, onSelect

onSubmit

Page 8: Javascript

8  

ANS: onSubmit, onReset 

 

Code function getRandom() { tdy = new Date(); var bigN=tdy.getSeconds()*tdy.getTime(); bigN *= Math.sqrt(tdy.getMinutes()); var randN = (bigN % 4) + 1; return Math.floor(randN); }

Which one of the following does the above function return?

A number (any type) between 1 and 5

The number 0

An integer between 1 and 4

An integer between 0 and 5

A number (any type) between 0 and 4

Ans : An integer between 1 and 4

Sample Code function checkField(field1, field2) { if ((field1 == "") && (field2 == "")) return true; else if ((field1 == "") || (field2 == "")) return false; else return true; }

When is a form that uses the above function in returning from its onclick event NOT submitted?

1 When field1 is not empty and field2 is not empty 2 When field1 is empty and field2 is not empty 3 When field1 is empty and field2 is empty 4 It will never be submitted. 5 It will always be submitted.

ANS : When field1 is empty and field2 is not empty. 

The "length" property of the frames object refers to which one of the following?

The height in pixels of the frame

The total pixels (H times W) of the frame

The size of the frames array

The length of the frame's name property

The amount of time used to load the frame object

Page 9: Javascript

9  

ANS : The size of the frames array 

 

Which event handler is NOT VALID for the Textarea DOM object?

onChange

onFocus

onClick

onBlur

onSelect

ANS : onClick 

 

 

Which one of the following is a benefit of using javascript for form validation?

Form data is encoded for transmission to an HTTP server.

It reduces network congestion, server load, and overall response time.

It provides for location specific string comparisons.

It automatically decodes encoded form data when there is an error.

It reduces client workload.

Ans : It reduces network congestion, server load, and overall response time. 

 

 

Sample Code x = 1; y = 2; x = (++x ^ y--);

What is the value of x after execution of the above code?

-2

-1

0

1

2

Ans: 0 

 

Page 10: Javascript

10  

Sample Code x = 1; y = 2; z = 3; x = (x << 2) + (y >> 1) * (z << 1);

What is the value of x after execution of the above code?

10

11

12

13

14

ANS: 10 

 

 

Sample Code var bool1 = true; var bool2 = false; var bool3 = false;

Referring to the above, which one of the following statements is true?

bool1 && bool3

bool2 ^ bool3

bool3 || bool2

bool2 = bool1

bool1 & bool2 ANS: bool2 = bool1

 

 

Code var ch1 = 'b'; var ch2; switch(ch1) { case 'a': ch2 = '1'; break; case 'b': ch2 = '2'; case 'c': ch2 = '3'; break; default: ch2 = '4'; }

Referring to the above code, what is the value of "ch2" after execution?

'1'

Page 11: Javascript

11  

'2'

'3'

'4'

null

ANS: ‘3’ 

 

Sample Code var testSample = "Hello There!"; var result = testSample.slice(3, 7);

Referring to the sample code above, what is the value of "result" after execution?

'lo T'

'lo Th'

'llo Th'

'llo '

'llo T'

ANS: ‘lo T’ 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- var i; Object.prototype.array = new Array(3); var o = new Object(); o.array[0] = "2"; o.array[1] = "4"; o.array[2] = "6"; . . . <CODE HERE> // --> </SCRIPT>

Referring to the above, which code fragment loads i with the value of the second array element?

i = o.array(2);

i = o.prototype.array[2];

i = o.array["1"];

i = o.prototype.array[1];

i = o.array(1);

ANS: i = o.array["1"]; 

 

Page 12: Javascript

12  

 

 

What code removes every 'x' from String "S"?

var myArray = S.clear('x'); S = myArray.join('');

var SCopy = ''; for(var i = 0; i < S.length; i++) if(S.charAt(i)!='x') {SCopy += S.charAt(i); S = SCopy;

while(i=1;i<S.length; i++) if(S[i] != 'x') S == S[i];

dowhile(var i=1; i<S.length; ++i) if(S[i] != 'x') S == S[i];

for(var i = 1; i < S.length; i++) { if(S.char(i) == 'x') S += S.charAt(i); }

ANS:Option 2

var SCopy = ''; for(var i = 0; i < S.length; i++) if(S.charAt(i)!='x') {SCopy += S.charAt(i); S = SCopy; 

 

How do you get any URL arguments passed in through the URL?

Parse the URL.

document.url.getArgs()

document.url.args

window.args

window.document.args

ANS: Parse the URL 

 

Which one of the following is NOT a method or property of the "history" object?

go()

list

forward()

length

back()

ANS: list 

 

Page 13: Javascript

13  

 

 

Which one of the following is a client-side JavaScript object?

Database

Cursor

Client

FileUpLoad

Retrieve

ANS: FileUpLoad 

 

What code produces HTML output that displays an image?

document.write(IMG SRC="test.gif");

document.write(<IMG SRC="test.gif">);

document.write("IMG SRC='test.gif'");

document.write(<IMG SRC='test.gif'>);

document.write('<IMG SRC="test.gif">');

ANS: OPTION 5 

 

How long does a cookie WITHOUT an expiry date last?

Until the browser is closed

Until the current document is unloaded

Until it gets an expiry date that is expired

Until it is erased

It lasts forever.

Ans: Until the browser is closed

 

 

Code total=0; for(var j=0;j<10;j++) { for(var i=0;i<3;i++) total++; }

What is the value of "total" after execution of the code above?

Page 14: Javascript

14  

0

24

27

30

33

ANS: 30 

 

ample Code function Square(length) { this.length = length; } function Square_area() { return this.length*this.length; }

Referring to the above, which one of the following code segments adds the Square_area function to the Square object as a property?

Square.prototype.area = Square_area;

Square.addProperty("area", Square_area);

Square.addProperty(Square_area);

Square.area(Square_area);

Square.area = Square_area;

ANS: Square.prototype.area = Square_area; 

 

Which one of the following attributes CANNOT be removed when opening a new window?

Location Box

Status

TitleBar

MenuBar

ScrollBars

ANS:TITLEBAR

 

 

 

 

 

Page 15: Javascript

15  

 

 

 

What code forces the full frameset to show when a page that is part of a frameset is loaded?

if(location==top.location) top.location.href="frameset2.html"

if(location==self.location) href="frameset2.html"

if(self.location==top.location) self.location.href="frameset2.html"

if(parent.location==self.location) parent.location.href="frameset2.html"

if(top.location==self.location) top.location.href="frameset2.html"

ANS: if(top.location==self.location) top.location.href="frameset2.html" if(self.location==top.location) self.location.href="frameset2.html" (most probably)

 

 

Sample Code var testDate = new Date();

What does the above variable testDate contain?

A Date object with a date of when it was created

A function to create a new Date object

An empty Date object with no assigned date

A Date variable waiting to get a Date object assigned to it

A string object representing the Date object created

Ans: A Date object with a date of when it was created 

 

Code document.write('This text \\n is output\n')

Which one of the following statements is equivalent to the code above?

document.write('This text \n'); document.write(' is output\n')

document.write("This text is output")

document.writeln("This text \\n is output")

document.writeln('This text is output")

document.writeln('This text is output')

Ans: document.writeln("This text \\n is output")

 

 

Page 16: Javascript

16  

Code var sample="test"; var result=sample.big();

Referring to the above code, what is the value of "result" after execution?

TEST

<BIG>test</BIG>

<BIG>TEST</BIG>

test

Unable to tell--big() is not defined.

ANS: test

 

 

Sample Code x = 0; y = 0; while (x < 5) { x++; y = x ^ 15; }

What is the value of y after execution of the above code?

0

1

5

10

12

ANS: 10 

 

 

For which one of the following is an object's prototype property used?

To create a new object instance in testing code

To test a new object after creating an instance

To import an object from another file

To allow inheritance

To create a new object type

ANS: To create a new object type

Page 17: Javascript

17  

Code 1. function factorial(num) { 2. var f = 1; 3. for(i=2;i<=num;i++) { 4. f += i; 5. } 6. return f; 7. }

Referring to the above code, function factorial should return the factorial of "num." Which line contains an error?

Line 1 Line 3 Line 4 Line 5 Line 6

ANS: Line 4

function wContent(thisPage) { parent.content.document.write("<HTML>" + "<HEAD></HEAD>"); parent.content.document.write("<HEAD>"); parent.content.document.write("<BODY>"); parent.content.document.write("Page "+ thisPage+".</BODY></HTML>"); parent.content.document.close(); }

The function above represents which one of the following concepts?

Local Data Types

Static Data Loading

Passing Frame Information

Dynamic Page Creation

Virtual Functions ANS: Dynamic Page Creation

Code var name = prompt("What is your name?","name"); var query = ""; document.write("<H1>" + name + "'s 10 favorite foods</H1>"); for(var j=1; j<=10; j++) { document.write(j + ". " + prompt('Enter food number ' + j,'food') + '<BR>'); }

Of people who visit a website site about their top 10 favorite foods, which one of the following is true of the above code?

Page 18: Javascript

18  

It prints links to the user's ten favorite food web sites.

It tells visitors about their top 10 favorite foods.

It queries visitors about their top 10 favorite foods.

It informs users of the author's name and food preferences.

It asks for a password ten times.

ANS: It queries visitors about their top 10 favorite foods.

 

 

Code var circumference; var radius = 10;

Referring to the above code, what code calculates the circumference of a circle (2 * pi * radius)?

circumference = 2 * Math.PI * radius

circumference = 2 * (new Math().getPi()) * radius

circumference = Math.PI * Math.sqr(radius)

circumference = 2 * (new Math().PI) * radius

circumference = 2* Math.getPi() * radius

ANS:  var circumference;

var radius = 10; circumference = 2 * Math.PI * radius 

 

Code var newWindow = open(url, title, args);

To which one of the following does newWindow.opener refer in the above code?

The URL with which newWindow is opened

The navigator object

newWindow itself

The top window

The window that opened newWindow

ANS: The window that opened newWindow

 

 

What is the value of window.name when run in the original browser window?

'undefined'

'self'

Page 19: Javascript

19  

'Document 1'

'window'

''

Ans: “ 

 

 

 

ample Code var x, y; for (x = 0; x <= 5; x +=2) for (y = 0; y <= 5; y++) if (y > 3) continue;

After executing the above code segment, what is the value of y?

3

4

5

6

7

Ans: 6

 

 

 

Sample Code document.writeln(eval(new String("22") + " + " + new String("5")));

What does the above code segment output?

undefined

Nothing

225

22 + 5

27

Ans: 27 

 

Which one of the following is NOT a used to emulate an event?

focus()

submit()

Page 20: Javascript

20  

select()

load()

click()

ANS: submit() load()

 

 

 

 

 

Sample Code x = 0; y = 0; for (x = 0; x < 4; x++) { switch (x) { case 0: break; case 1: y = 2 << x; break; case 2: y *= x; break; default: y += x; break; } }

What is the value of y after execution of the above code?

0

1

2

11

12

Ans: 11 

 

Sample Code var total=0; for (var x = 1; x < 5; x = x << 1) { total += x; }

What is the value of "total" after execution of the above code?

0

Page 21: Javascript

21  

1

3

7

15

ANS: 7

 

 

 

 

 

Sample Code <FORM action="someAction" method="POST" name="TestForm"> <SELECT name="TestSelect" MULTIPLE > <OPTION selected>Option 1</OPTION> <OPTION>Option 2</OPTION> <OPTION>Option 3</OPTION> <OPTION selected>Option 4</OPTION> </SELECT> </FORM>

Referring to the above code, how do you clear all items selected?

document.TestForm.TestSelect.clear();

document.TestForm.TestSelect.multiple = false;

document.TestForm.TestSelect.selected = false;

document.TestForm.TestSelect.options.clear();

document.TestForm.TestSelect.selectedIndex = -1;

ANS: document.TestForm.TestSelect.options.clear();

document.TestForm.TestSelect.selectedIndex = -1; 

 

Which one of the following code segments displays the value of the third element of the second form in the parent frame?

document.output(parent.document.forms[2].elements[3].value);

document.writeln(parent.document.forms[1].elements[2].value);

document.writeln(parent.document.forms[2].elements[3].value);

document.writeln(parent.document.forms[2].elements[3].getValue());

document.writeln(parent.document.forms[1].elements[2].getValue());

ANs: document.writeln(parent.document.forms[1].elements[2].value);

 

Page 22: Javascript

22  

 

Which one of the following statements does NOT declare a variable named "test"?

var test

var test = 10

test = 10

var test = x

var.test

ANS: var.test 

 

 

 

Which one of the following core objects is used for pattern matching?

Format

String

RegExp

StringFormat

Pattern

ANS: RegExp 

 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- function onChecked() { if (document.CheckboxForm.On.checked) document.CheckboxForm.Off.checked = false; else

Page 23: Javascript

23  

document.CheckboxForm.Off.checked = true; } // --> </SCRIPT> <FORM NAME="CheckboxForm"> <INPUT TYPE="checkbox" NAME="On" onClick="onChecked();"> <INPUT TYPE="checkbox" NAME="Off"> </FORM>

Referring to the above, what happens when the "On" checkbox is checked for the first time?

The "Off" checkbox is checked.

The "On" checkbox is unchecked.

The "Off" checkbox is reversed.

The "Off" checkbox is unchecked.

Nothing happens.

ANS: Nothing happens. 

 

 

 

 

Sample Code <FORM METHOD="POST" NAME="TestForm" ACTION="/cgi-bin/process.cgi" TARGET="frame2"> <INPUT TYPE="submit" VALUE="Submit"> </FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- document.TestForm.target = "frame1"; // --> </SCRIPT>

Where do the results from submitting the above form go?

To a new window

To a target named 'frame2'

To the topmost window

To a target named 'frame1'

To the same frame in which the form is

ANS: To a target named 'frame2'

To a target named 'frame1' 

 

Code var s = "test"; s.big(); s.blink(); s=s.bold();

Page 24: Javascript

24  

s=s.strike(); s=s.fontsize(7); document.write(s.italics());

Referring to the above code, the html document shows the word "test" with what style characteristics?

Blinking, bold, strikethrough, size 8, and italic

Default styles for browser

Bold, strikethrough, size 7, and italic

Size 7 and italic

Italic

ANS: Bold, strikethrough, size 7, and italic

 

Code var i=0; for(j=0;j<=10;j+=5;) { i++; }

Referring to the above code, what is the value of "i" after execution?

0

2

3

10

11 ANS:3

 

ode expires=new Date(); expires.setTime(expires.getTime() + 24 * 60 * 60 * 365 * 1000); document.cookie = "c1=data; expires=" + expires.toGMTString();

Referring to the above code, when does cookie "c1" expire?

In 1 month

In 1 year

In 24 years

In 1000 years

Immediately

ANS: In 1 year 

 

Code function setvals(object s) {

Page 25: Javascript

25  

s.name = "John"; s.age = 15; s.id = 100; } setvals(student);

Referring to the above code, the object "student" has how many properties?

1

2

3

At least 3

More than 3

ANS: At least 3 

 

Which one of the following events can be used to display a confirmation box when a user submits a form?

onChange

onSubmit

onForm

onReset

onMouseover

ANS: onSubmit 

 

Which is a "string" property?

substring

size

name

length

value

ANS: length 

 

testText = "This is";  

testMessage = testText + " " + new Number(4) + " pages long!"; 

alert(testMessage); 

Page 26: Javascript

26  

ANS: This is 4 pages long! 

Of which one of the following is the keyword "delete" used?

To delete a property from an object

To delete the defaults in the document

To delete all the images for a lower bandwidth

To delete a variable from within a function

To delete a file on the client computer ANS To delete a property from an object delete The delete operator is used to delete an object, an object's property or a specified element in an array, returning true if the operation is possible, and false if not. With the defined object 'fruit' below, the following delete operations are possible:

Q:

var total=0; for(var j=0;j<5;j++) { for(var i=0;i<3;i++) { if(j > 3) total--; else total++; } }

What is the value of "total" after execution of the code above?

0

6

9

12

30 ANS: 9

Which code segment changes the background color of the third frame to white?

self.frames[2].bgColor = "white";

self.frames[2].document.bgColor = "0xFFFFFF";

self.frames[3].document.bgColor = "0x000000";

self.frames[2].document.bgColor = "0x000000";

self.frames[3].document.bgColor = "white";

ANS; WRONG OPTIONS - self.frames[3].document.bgColor = "white";

self.frames[2].document.bgColor = "0xFFFFFF";

Setting a new value to which one of the following redirects the browser to a new URL.

Page 27: Javascript

27  

document.URL

document.location.href

location.URL

window.location.href

link.href

ANS: document.location.href

Q:<html> 

<body> 

<script type="text/javascript"> 

x = 0;  

</SCRIPT>  

<SCRIPT language="JavaScript" src="external.js">  

for ( ; x < 20; x += 3 )  

 x++;  

x = x * 3;  

document.write(x); 

</SCRIPT>  

<SCRIPT language="JavaScript">  

x = x * 10;  

document.write(x); 

</script> 

</body> 

</html> 

Ans: 0 

 

Q:<FORM METHOD="POST" ACTION="/cgi-bin/process.cgi" NAME="TestForm"> <INPUT TYPE="hidden" NAME="first">

Page 28: Javascript

28  

<INPUT TYPE="hidden" NAME="second"> <INPUT TYPE="hidden" NAME="third"> </FORM>

Referring to the above, what does document.TestForm.elements[document.TestForm.length] return?

'first' input object

'second' input object

'third' input object

undefined

An error dialog is displayed. ANS: undefined

Password inherits from which one of the following classes?

Textarea

Hidden

Input

String

Login ANS: Hidden Input

Code function callOther(){ return (otherToCall()); } function otherToCall(){ var x = 2, y = 5; return (x + y); }

Referring to the above, what is returned when callOther is called?

7

25

null

undefined

An error occurs c5-mc. ANS 7

Page 29: Javascript

29  

Functions can be created as objects and assigned to a variable using which one of the following constructors?

Inherit

This

new

Function

set ANS: new (it should be- Function)Pooja as I have referred from the book… Function

What event handling code can create forward and back buttons in an HTML that behave as the browser toolbar?

back: onClick="history.go(-2);"> forward: onClick="history.forward;">

back: onClick="history.back();"> forward: onClick="history.forward();">

back: onMouseOver="history.back(-1);"> forward: onMouseOver="history.forward(0);">

back: onMClick="history.go;"> forward: onMClick="history.forward;">

back: onClick="history.go(0);"> forward: onClick="history.forward(0);"> ANS: back: onClick="history.back();"> forward: onClick="history.forward();">

Code var name=prompt("Promt msg","Hello")

Referring to the above code, what code displays the value of "name" in a document?

window.document.name.write();

write(name);

document(name);

window.name.write();

Page 30: Javascript

30  

document.write(name); ANS: document.write(name);

5;

Referring to the above code, what is the value of variable "x"?

0

.1

.2

.3

.5 ANS: .1

Which one of the following code segments is used to compute x to the power of y?

Math.pow(x, y)

x ** y

x ^ y

y ^ x

Math.exp(x, y) ANS: Math.pow(x, y)

ject is often used to enable Html documents to have buttons that highlight when the mouse hovers over them?

<SCRIPT LANGUAGE="JavaScript"> <!--

Page 31: Javascript

31  

function testVariable(x) { var returnVar; switch (x) { case 1: returnVar = 'one'; case 2: returnVar = 'two'; case 3: returnVar = 'three'; case 4: returnVar = 'four'; default: returnVar = 'none'; } return (returnVar); } // --> </SCRIPT>

What value does the above function return if x is passed into it as 2?

'one'

'two'

'three'

'four'

'none' ANS:’none’

Q:function submitIt(form) { dOpt = -1; for(j=0; j<form.DCt.length;j++) { if(form.DCt[j].checked) dOpt = j; } if(form.DCt[dOpt].value == "4Door" && form.sunroof.checked) { alert("sunroof is not available" + " on the 4 door model"); return false; } return true; }

Referring to the above code, what type of form elements are "4Door" and "sunroof," respectively?

Text field, checkbox

Pull-down menu option, pull-down menu option

Pull-down menu option, radio button

Radio button, checkbox

Check box, text field ANS:Radio button, checkbox

'checked' is applied to

Page 32: Javascript

32  

+----------------+--------------------------------------------------------------+| Applied_To |<input type="checkbox"> <input type="radio"> |+----------------+--------------------------------------------------------------+

Q:<SCRIPT LANGUAGE="JavaScript"> <!-- var x = new Number(16); var y = x.toString(15); // --> </SCRIPT>

What does y contain after execution of the above code?

"0"

"10"

"11"

"15"

"16" ANS: “11”

e Code var x = 9; x = x >> 2; x = x << 2; x = x ^ 3;

What is the value of x after the above code is run?

8

11

27

512

729 ANS:11

Page 33: Javascript

33  

Q: pgAry=new Array("","3a.htm","3b.htm","3c.htm");

What code follows the above code in the <HEAD> section of a frame that serves as a navigation bar to load contentframe?

function setContent(this.Pg) { content.document.href = pgAry[this.Pg]; }

function setContent(thisPg) { parent.content.document.href = pgAry[thisPg]; }

function setContent(thisPg) { parent.document.location = pgAry[thisPg]; }

function setContent(thisPg) { parent.document.location.href = pgAry[this.Pg]; }

function setContent(thisPg) { parent.content.document.location.href= pgAry[thisPg]; } ANS: function setContent(thisPg) { parent.content.document.href = pgAry[thisPg]; } } function setContent(thisPg) { parent.content.document.location.href= pgAry[thisPg]; }

e Code <FORM NAME="TestForm"> <INPUT TYPE="checkbox" NAME="check" onClick="document.TestForm.check.checked = false; return true;"> <INPUT TYPE="submit" VALUE="Submit"> </FORM>

Which one of the following is true about the above form?

The checkbox is always unchecked.

Clicking the checkbox will submit the form.

The checkbox is always checked.

It has one element.

It uses the POST method as default. ANS: The checkbox is always unchecked.

/* document.writeln("a"); document.writeln("b"); */ document.writeln("c");

Page 34: Javascript

34  

document.writeln("d"); // document.writeln("e"); /**/ document.writeln("f");

Referring to the above, what does the user see in the browser output?

a b c d e f

c d

c d e f

c d f

d f

ANS: c d f 

 

 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- var y; function modifyVariables(x) { var z = 5; x += 2; y += x + z; } // --> </SCRIPT> . . . <SCRIPT LANGUAGE="JavaScript"> <!-- var x = 1; var y = 2; var z = 3; modifyVariables(x); document.writeln(x); document.writeln(y); document.writeln(z); // --> </SCRIPT>

What is the output after the above scripts are run?

1 10 3

3 8 3

1 8 3

1 2 3

Page 35: Javascript

35  

3 10 3

Ans: 1 10 3

Sample Code <INPUT TYPE="button" onClick="document.location.href = document.links[1].href; return false;">

What is the above code segment simulating?

Clicking on the second link in the document

Going back to the previous document

Reloading the document from the link into this document

Submitting the form

Resetting the form Ans: Clicking on the second link in the document I want to change the page by attaching an onclick event to an HREF, like this: Quote:

<a href="" onclick="document.location.href = 'http://www.cnn.com/'"> test</a>

If you do it that way you need to return false <a href="" onclick="document.location.href = 'http://www.cnn.com/' ; return false"> test</a>

Which one of the following is NOT an event handler for DOM objects?

ondragdrop

onload

onexit

onblur

Onerror ANS: onexit

Q: <SCRIPT LANGUAGE="JavaScript"> <!-- var x = 0, y = 0, z = 0; document.writeln(x++); document.writeln(++y); document.writeln(--x + ++z); // --> </SCRIPT>

Page 36: Javascript

36  

What is output from the above code segment?

0 1 1

1 1 0

0 0 0

0 1 0

1 1 1 ANS: 0 1 1

What is the INDEX of the last frame in a frames[] array?

parent.frames.[3]

parent.frames[]

parent.frames.last

parent.frames.length

parent.frames.[NULL] ANS:parent.frames.length

Code for(i=0;i<sp.length;i++) if(chk==sp.charAt(i)) return true; return false;

What code is equivalent to the code above?

return(sp.lastIndexOf(chk,chk.length)==0 ? false:true)

if(sp.indexOf(chk,0)>=0) out=true; return false;

return(sp.indexOf(chk,chk.length)<=0 ? false:true)

if(sp,lastIndexOf(chk,chk.length)>0) return(true); return false;

return(sp.indexOf(chk, 0)<0 ? false:true ANS: return(sp.indexOf(chk, 0)<0 ? false:true

 

Sample Code

var testString = "Hello World!"; var x = testString.lastIndexOf("l", 0);

Page 37: Javascript

37  

What is the value of x after execution of the above code segment?

-1

2

3

9

10 ANS: -1

Which one of the following code segments sets the checkbox1 in form1 to "checked" if the checkbox1 in a sibling document in form1 is checked?

if (top.sibling.document.form1.checkbox1.checked) self.document.form1.checkbox1.checked = true;

if (top.sibling.document.form1.checkbox1.checked) document.sibling.document.form1.checkbox1.checked = true;

if (window.sibling.document.form1.checkbox1.checked) self.document.form1.checkbox1.checked = true;

if (self.document.form1.checkbox1.checked) parent.sibling.document.form1.checkbox1.checked = true;

if (parent.sibling.document.form1.checkbox1.checked) self.document.form1.checkbox1.checked = true ANS: if (parent.sibling.document.form1.checkbox1.checked) self.document.form1.checkbox1.checked = true

Sample Code var plane = new Plane();

Referring to the above, what is the one way to create a new property called "engine" for the "plane" instance object?

plane.property = new Engine();

new Engine(plane);

plane.property(new Engine());

plane.engine = new Engine();

plane(new Engine()); ANS: plane.engine = new Engine();

What code automatically scrolls (vertically) a document 100 pixels down when it is loaded in a window?

setTimeout('newWindow.scroll(100,0)',100)

setTimeout('newWindow.scroll(0,100)',1000)

Timeout(newWindow.scroll(100),1000)

setTime('newWindow.scroll(100,0)',100)

scroll(newWindow(0,100),100) ANS: setTimeout('newWindow.scroll(0,100)',1000)

Page 38: Javascript

38  

Which of the following DOM object or objects are associated with the onFocus event handler?

Password

Password and Hidden

Parent

Hidden

Hidden and Parent ANS:PASSWORD

Which objects CANNOT be included in a form object?

document

submit

FileUpload

select

Radio ANS:document

You need UniversalBrowserWrite privilege in order to do all of the following EXCEPT which one?

Open a window smaller than 100 pixels on a side

Change the location bar, directory bar, or personal bar of the browser

Change the properties of and Event object

Read the preferences with the Navigator.preference() method

Change the menubar, status line, or toolbars of the browser ANSWER: Read the preferences with the Navigator.preference() method (doubt fr this answer, don’t know d correct answer- POOJA)

What does the export keyword do?

It creates a Java bytecode file for the exported content.

It writes the script to a file.

It allows access from another execution context.

It takes all imported parameters and sends them to the specified program.

It tells a script which core objects to unload. ANS: It allows access from another execution context.

Q:unescape(argument);

Page 39: Javascript

39  

Which one of the following is true of the above statement?

It replaces Html character entities such as &amp;nbsp; with their printed characters.

It removes all url encoding from a string.

It removes line breaks from a string.

It prevents the user from leaving the current document.

URL encodes the value property of the "argument" object. ANS: It removes all url encoding from a string.

Q:j = 0; total = 0; do { j++; total = total ^ j; } while (j < 2);

What is the value of "total" after execution of the above code?

0

1

2

3

4

ANS:3 

Which method is used to end a document's output stream?

window.close()

window.end()

document.close()

window.close(window.document)

document.end() ANS: document.close()

Page 40: Javascript

40  

function getRandom() { tdy = new Date(); var bigN=tdy.getSeconds()*tdy.getTime(); bigN *= Math.sqrt(tdy.getMinutes()); var randN = (bigN % 4) + 1; return Math.floor(randN); }

Which one of the following does the above function return?

A number (any type) between 1 and 5

An integer between 1 and 4

A number (any type) between 0 and 4

The number 0

An integer between 0 and 5 ANS: An integer between 1 and 4

Q:<FORM NAME="TestForm"> <INPUT TYPE="hidden" NAME="hiddenInput"> <INPUT TYPE="button" VALUE="Change Input" onClick="changeValue(this.form);"> <INPUT TYPE="submit" VALUE="Submit"> </FORM>

Referring to the sample code above, which one of the following functions assigns another value to the hidden input?

function changeValue(f){ var j = prompt("New Value", ""); f.hiddenInput = j; }

function changeValue(f){ var j = prompt("New Value", ""); f[hiddenInput].value = j; }

function changeValue(f){ f[hiddenInput] = prompt("New Value", ""); }

function changeValue(f){ f.hiddenInput.value = prompt("New Value", ""); }

function changeValue(f){ var j = prompt("New Value", ""); f.forms.hiddenInput.value = j; }

ANS: function changeValue(f){ f.hiddenInput.value = prompt("New Value", ""); }

Page 41: Javascript

41  

Q:Which one of the following is true of an event?

It is the execution of any function.

It is a signal generated when a specific action occurs.

It is the start of any script block execution.

It is a user-generated action.

It is the execution of any script statement. ANS:It is a signal generated when a specific action occurs.

Sample Code var x = 0; var y = 3;

Referring to the above code, which one of the following is true?

x == y - 3

x = y

y < x

x * y > 0

y * -3 > 0 ANS: x == y - 3

Sample Code <FORM action="someAction" method="POST" name="TestForm"> <SELECT name="TestSelect" MULTIPLE > <OPTION selected>Option 1</OPTION> <OPTION>Option 2</OPTION> <OPTION>Option 3</OPTION> <OPTION selected>Option 4</OPTION> </SELECT> </FORM>

Q:

<script language=javaScript> function surfto(form) { var idx=form.s1.selectedIndex if(form.s1.options[idx].value != 0) location=form.s1.options[idx].value; } </SCRIPT><FORM name="form1">

Page 42: Javascript

42  

<SELECT name=s1 onChange="surfto(this.form)" size=1> <OPTION selected value=0>Choose One <OPTION value=u2.htm>U2 <OPTION value=u3.htm>U3 <OPTION value=u4.htm>U4</SELECT> </FORM>

Pull down with 4 choices

Which property is used to access the number of elements in a form?

elements

method

length

count

number ANS: length

Sample Code var testVar = Math.ceil(Math.random() * 100);

Referring to the above, what is range of variable "testVar"?

-99 to 100

0 to 99

0 to 100

1 to 99

1 to 100 ANS: 1 to 100

Page 43: Javascript

43  

Generally speaking, the "onUnload" event handler is used to do which one of the following?

Choice 1

Remove a document from browser cache

Choice 2

Unload an HTML document

Choice 3

Perform actions after a document is unloaded

Choice 4

Perform actions before a document is unloaded

Choice 5

Close a window or frame objects (I think itz answer is option 5 please verify- Pooja) Perform actions before a document is unloaded

Home

You are here: Duckware » Java Applets » Reference Contact us

JavaTM Applet Reference

1. The Java <APPLET> HTML Tag 2. Applet Security Model 3. Technical Notes

1. The Java <APPLET> HTML Tag

Page 44: Javascript

44  

· PrintEnvelope · WinOpen · Label Java Applets · Reference · Scripting · ControlPad Learning + Fun · NX 101 · Pano Help · Bug Free C · Space Rocks

To embed any Java applet within an HTML web page, you must use the <APPLET> tag. See the table to the right for the <APPLET> tag syntax (grayed options are optional; bold text is used as-is; italic text is information that you must provide). code=class-filename -- code="pmvr.class" -- The filename of the applet to load (which always ends in .class). It will load from the directory/folder listed by the codebase attribute listed below. width=pixels -- width=500 -- The width, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is. height=pixels -- height=250 -- The height, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is. archive=jar-file -- archive="pmvr.jar" -- The name of a jar file, which contains the *.class files for you applet. Note that files in the JAR must be in stored format (no compression). Otherwise, if you use compression, you limit yourself to Java 1.1 or later compatibility. name=instance-name -- name="pmvr" -- Your name for the applet, which can be any text that makes sense to you. This allows applets wweb page to find each other and it allows for you to control the applets via JavaScript. This attribute is optional. codebase=url -- codebase=".." -- The URL to the directory/folder containing the applet code (class files). An absolute URL can be speci(useful for hosting PMVR tours on multiple domains). A relative URL allows the applet to work on both web servers and the local file systeThe relative URL is relative to the document's base URL defined by the BASE tag. If the document does not define a BASE tag, it is relativthe directory/folder containing the HTML file. align=alignment -- align="left" -- The alignment of the applet. It behaves (and has the same options) as the IMG tag align attribute.attribute is optional. vspace=pixels -- vspace=3 -- The vertical space, in pixels, between the applet and surrounding text. It behaves the same as the IMG tavspace attribute. This attribute is optional. hspace=pixels -- hspace=3 -- the horizontal space, in pixels, between the applet and surrounding text. It behaves the same as the IMG hspace attribute. This attribute is optional. MAYSCRIPT -- This attribute allows you to use JavaScript within an applet. If you want to use JavaScript, you must grant the applet accesJavaScript by using the MAYSCRIPT attribute, otherwise the applet is not permitted to use JavaScript. If you use MAYSCRIPT on one applweb page, you will need to use MAYSCRIPT on all applets in the web page. Please refer to the 12/30/1999 tech note [§3] for details. <param name=parameter value=value> -- Applet parameters are used to configure an applet. Just use as many param tags as needed toconfigure the parameters (the parameters are always specific to the particular applet you are using). Please note that param tags are defwithin the APPLET tag. AlternateHTML -- If the <APPLET> tag is not supported by a web browser, the HTML in this section will be displayed. Otherwise, the applshown and the HTML in this section is ignored. For more information about the <APPLET> tag, visit Sun's Applet tag reference. 2. The Java Applet Security Model A Java VM (virtual machine) is what allows Java applets to run within web browsers. And all modern web browsers come with a Java VM.applets are safe to run on your computer because the Java VM prevents a Java applet from accessing resources (files/network/memory/ethat it is not authorized to access. Applets can be run in a web browser either from a web server, or from the local file system (disk/CD). Web Server: When a Java VM runs a Java applet from a web server, the Java applet is authorized to access any file on the web server tthe applet came from, but the applet can not access any file on another web server or any file on the local file system (your PC). Local File System: However, when a Java VM runs a Java applet from a local file system (your hard drive), the Java applet is authorizedaccess only files in the directory that the applet came from (or any subdirectories). Also, the Java VM prevents an applet from accessing the root of any drive/CD, as detailed in the 06/20/2000 tech note [§3], as operating system (OS) configuration files (config.sys, autoexec.bat, etc) are usually located there. For example, the following table summarizes what an applet, running from an HTML file test.html in the tours directory (with the class placed in the same tours directory) is allowed to access:

<applet code=class-filename width=pixels height=pixels archive=jar-file name=instance-name codebase=url align=alignment vspace=pixels hspace=pixels MAYSCRIPT > <param name=parameter1 value=va <param name=parameter2 value=va . . . alternateHTML </applet>

Page 45: Javascript

45  

Can an applet in test.html (in tours folder) access...

this image when run from http://www.xyz.com/tours/ c:/tours/

../pan1.jpg yes NO

../images/pan2.jpg yes NO

./pan3.jpg yes yes

./images/pan4.jpg yes yes

http://www.xyz.com/any.jpg NO NO

Notice the discrepancy in access to pan1.jpg and pan2.jpg. Depending upon where test.html is accessed from (a web server or the lochard drive), access to the same image can be either allowed or denied. The problem is that running from the local hard drive is more restrictive than running from a web server. Because when running from a local hard drive, only files in the same directory as the applet cfiles (or subdirectories) can be accessed by the applet. With proper planning, and by using the Java applet codebase tag, this problem can be avoided. Namely, create all tours within a directorand use the codebase attribute within any <APPLET> tags [§1] in HTML to refer back to the one set of Java class files in the root of the directory tree you created.

3. Java Applet Technical Notes Java Console TIP: If you are experiencing problems with an applet, the first step is to open the 'Java Console' in your browser to checkerror messages:

• Internet Explorer (Sun's Java): The Java Console option appears under the Tools menu. • Firefox: Right click on the Java tray icon and select 'Java Console'. • Netscape Communicator: The Java Console is located in the 'Tools / Web Development' menu (or under 'Communica

menu in older versions). • Internet Explorer (Microsoft Java): The Java Console must first be enabled in 'Tools / Internet Options / Advanced

Microsoft VM / Java console enabled'. After restarting your browser, the 'Java Console' option will be available under th'View' menu.

03/28/2006 -- Activating ActiveX Controls (Java) in Internet Explorer -- Microsoft has changed how user's interact with ActiveX controls on web pages. Previously, you could interact immediately with controls. However, now there is an extra click. Full details and a workaround. NOTE: the need for this extra click has been removed by Microsoft in April 2008. 01/04/2006 -- Internet Explorer on Mac should no longer be used -- Microsoft's Internet explorer for the Mac is no longer a produApple's Safari web browser should be used instead. 02/19/2001 -- Java Applets Cannot Be JavaScript'ed in Mac Internet Explorer -- Microsoft Article ID Q190283 has complete detasummary, Microsoft does not support JavaScript to Java communication on the Mac. However, please note that Netscape on the Mac andApple's Safari web browser both do support scripting. To work around this problem, use a web browser that works, or use Native scriptininstead of JavaScript scripting. 10/30/2000 -- Do not use spaces in filenames -- Do not use spaces in the filenames of images, etc (possible under a Windows servit appears that this can cause problems with some browser / server combinations. Namely, using a URL with a space works under IE (theis automatically converted to %20), but fails under Netscape. 09/08/2000 -- Netscape cannot read some JPEGs -- Some people have reported that a panorama displays fine in Internet Explorerdoes not appear when using Netscape Navigator (and that the Netscape java console window reports a "sun.awt.image.ImageFormatException: Image too wide for this implementation" error). This particular problem has been tracedNetscape being unable to read the JPEG at all. To test this, create a URL that points directly to the JPEG image file on the server and testboth Netscape and Internet Explorer. If it does not appear in Netscape but it does within Internet Explorer, then you have run into this problem. The graphics program you are using is producing a JPEG that Netscape is unable to read! Whether this is a problem with the proyou are using to write the JPEG (but Internet Explorer works) or with Netscape is unknown. The work-around is to use another graphics program to write the JPEG. 06/24/2000 -- Avoid using transparent GIF images -- Make sure that you avoid using transparent GIF images in applets, if possibleappears that many Java VM's take a significant performance hit in order to display transparent GIF images. While transparent GIF imageswork, they may dramatically show down the applet and cause jerky displays. 06/20/2000 -- Files in the root of a drive/CD cause security errors -- If you attempt to locate class or image files into the root directory of a drive or CD, you will experience problems due to the Java applet security model [§2] (that prevents applets from accessing

Page 46: Javascript

46  

root of a drive or CD). The work-around is to move your class files and images into a directory/folder. 12/30/1999 -- MAYSCRIPT and Netscape -- If you use the MAYSCRIPT applet tag on one applet, you must use the MAYSCRIPT tag oapplets on a web page. This is due to a bug in the Netscape web browsers. If you use MAYSCRIPT in only one applet, a second applet canlonger communicate with the first. Please note that this bug only exists in the Netscape browsers and not in the Microsoft browsers.

Copyright © 2000-2009 Duckware

The "MAYSCRIPT" attribute of the HTML <APPLET> element is used to do which one of the following?

To create an applet To end a script when an error occurs To convert a script to binary code To replace an applet with an equivalent script To give a Java applet access to a JavaScript script

ANS- To give a Java applet access to a JavaScript script

Which one of the following is a correct way to create an instance of a Function object?

funct = new.Function() funct = new.Function funct = Function(new) funct == Function funct = new Function()

ANS: funct = new Function()

 

Page 47: Javascript

47  

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- var i, j; iloop: for (i = 0; i < 5; i++) { jloop: for (j = 0; j < 10; j++) { if (j > 4) break iloop; if (j > 3) break jloop; } } // --> </SCRIPT>

What are the values of i and j after execution of the above code?

i = 4, j = 4

i = 4, j = 3

i = 5, j = 4

i = 5, j = 3

i = 5, j = 5 ANS: i = 5, j = 4

Sample Code var x; x = 5 * 5 * 5 * 5 * 5;

Which one of the following is equivalent to the code above?

x = 5 + 5 + 5 + 5 + 5;

x = 5 ^ 5;

x = 5.toPower(5);

x = Math.pow(5,5);

x = Math.toPower(5,5); ANS: x = Math.pow(5,5);

Which one of the following code samples changes the method of TestForm to "GET"?

document.TestForm.method = "GET";

document.TestForm.onsubmit = "GET";

document.TestForm.method("GET");

document.TestForm.onsubmit("GET");

Page 48: Javascript

48  

document.TestForm.setMethod("GET");

ANS: document.TestForm.method = "GET"; 

Sample Code function openWindow(x, y, z) { window.open(x, y, z); }

When called, the above function opens a new window with which of the following?

A URL of "y," a title of "z," and features of "x."

A URL of "x," a title of "y," and features of "z."

A URL of "y," a title of "x," and features of "z."

A URL of "z," a title of "y," and features of "x."

A URL of "x," a title of "z," and features of "y."

  ANS: A URL of "x," a title of "y," and features of "z." 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- function goTo(url){ document.location.href = url; } // --> </SCRIPT> <FORM> <INPUT TYPE="button" onClick="goTo('link1.html'); return true;"> <INPUT TYPE="button" onClick="goTo('link2.html'); return true;"> <INPUT TYPE="button" onClick="goTo('link3.html'); return true;"> <INPUT TYPE="button" onClick="goTo('link4.html'); return true;"> <INPUT TYPE="button" onClick="goTo('link5.html'); return true;"> </FORM>

What does the above code create?

Five checkboxes and a button that loads the selected document when clicked

Five hyperlinks

A pull-down menu and a button that loads the selected document when clicked

Five buttons, each loading a corresponding URL when clicked

Five radio buttons and a button that loads the selected document when clicked ANS: Five buttons, each loading a corresponding URL when clicked

 

Page 49: Javascript

49  

Sample Code

<SCRIPT LANGUAGE="JavaScript"> <!-- var a = 2, b = -3, c = 5; var x = 1; if ((a + b) > c) x += 1; if (a > (b + c)) x += 1; if ((b > c) && (c > a)) x += 1; if ((c > a) || (b > c)) x += 1; // --> </SCRIPT>

What is the value of x after the above script is run?

1

2

3

4

5

ANS:2  

Sample Code var newWindow = open(url, title, args);

To which one of the following does newWindow.opener refer in the above code?

newWindow itself

The window that opened newWindow

The URL with which newWindow is opened

The top window

The navigator object ANS: The window that opened newWindow

The opener property returns a reference to the window that created the window 

The referrer property returns the URL of the document that loaded the current document 

The items in which one of the following pairs do the same thing?

history.go( history.length) and history.go(0)

history.forward() and history.go()

history.go(-2) and history.back()

history.back() and history.go(-1)

history.forward(1) and history.go(0)

Page 50: Javascript

50  

 

ANS: history.back() and history.go(-1) 

 

 

Which one of the following is true of local variables?

They are always in scope.

They are declared using the "var" command.

They are not accessible to sub-blocks.

They are only referenced inside the block in which they are declared.

They are accessible throughout the JavaScript code. ANS: They are only referenced inside the block in which they are declared.

Output One, Two..

What code produces the above output?

document.write("One,\nTwo..\n");

document.write('One,\nTwo..\n');

document.write('<PRE>One,\nTwo..\n</PRE>');

document.writeln("One,'); document.writeln('Two ');

<PRE>document.writeln('One,');document.write('Two ');<PRE> ANS: document.write('<PRE>One,\nTwo..\n</PRE>');

Code txt = new String("Sample text."); function textColor() { return "<FONT color='" + this.color + "'>" + this + "</FONT>"; }

Using the code above, what code assigns a "color" property to all string objects defaulted "gray" and facilitates printing colored text to a browser?

String.color = "gray"; String.colored = textColor;

Page 51: Javascript

51  

color.String = "gray"

String.txt.color = "gray"

String.color = "gray"

String.prototype.color = "gray"; String.prototype.colored = textColor; ANS: String.prototype.color = "gray"; String.prototype.colored = textColor;

Code function calc(form,fld) { var d = 0; if(fld == "r") { if(form.s.checked) { d=Math.sqrt(form.r.value); } else { d=form.r.value/2; } } else { if (form.s.checked) { d = form.e.value * form.e.value; } else { d = form.e.value * 2; } } return d; }

Referring to the above code, if checkbox "s" is checked, and parameter "fld" is equal to "q," what does function calc return?

"e" squared

"r" * 2

null

"r"/ 2

square root of "e" ANS: "e" squared

Q:<SCRIPT LANGUAGE="JavaScript"> <!-- var x; x = 1; <CODE HERE> // --> </SCRIPT>

Referring to the above, which one of the following code fragments will output the value of x?

window.output(x);

document.output(x);

window.writeln(x);

window.document.writeln(x);

String.output(x); ANS: window.document.writeln(x);

Page 52: Javascript

52  

Q:

<FORM METHOD="GET" onSubmit="return checkText(this);"> <INPUT TYPE="text" NAME="textObject"> <INPUT TYPE="submit" VALUE="Submit"> </FORM>

In the above code, to which one of the following does "this" refer?

document

textObject

checkText

form

window

ANS:FORM

Q:

i=0; total=0; while(i<4) { i++; if(i > 2) break; total += i; }

What is the value of "total" after execution of the code above?

0

1

2

3

6 ANS:3

Page 53: Javascript

53  

Q:If you wanted to put "Hello There!" on the status line, which one of the following code fragments does that?

self.status = "Hello There!"; return true;

self.status.value = "Hello There!"; return true;

self.document.status.setValue("Hello There!"); return true;

self.status.setValue("Hello There!"); return true;

self.setStatus("Hello There!"); return true; ANS: self.status = "Hello There!"; return true;

Page 54: Javascript

54  

1. 'url to open' This is the web address of the page you wish to appear in the new window.

2. 'window name' You can name your window whatever you like, in case you need to make a reference to the window later.

3. 'attribute1,attribute2' As with alot of other things, you have a choice of attributes you can adjust.

Window Attributes

Below is a list of the attributes you can use:

1. width=300 Use this to define the width of the new window.

2. height=200 Use this to define the height of the new window.

3. resizable=yes or no Use this to control whether or not you want the user to be able to resize the window.

4. scrollbars=yes or no This lets you decide whether or not to have scrollbars on the window.

5. toolbar=yes or no Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).

Page 55: Javascript

55  

6. location=yes or no Whether or not you wish to show the location box with the current url (The place to type http://address).

7. directories=yes or no Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...).

8. status=yes or no Whether or not to show the window status bar at the bottom of the window.

9. menubar=yes or no Whether or not to show the menus at the top of the window (File, Edit, etc...).

10. copyhistory=yes or no Whether or not to copy the old browser window's history list to the new window.

Q:<a href="map.htm" onMouseOver="window.status='Click for help!';">Site Map</a>

Which one of the following is true of the above code?

It opens a new status window with document text "Click for Help!"

It creates a hyperlink that says "Click for Help!"

Most browsers will interpret this as a syntax error.

It displays a help message in the status bar when mouse is over the hyperlink.

It does nothing because the JavaScript language is not specified.

ANS: It displays a help message in the status bar when mouse is over the hyperlink.

 

Which event handler or handlers are used to track a user's moves between fields in an HTML form?

Page 56: Javascript

56  

onFocus and onBlur onChange focus and blur load and unload onLoad and onUnload ANS: onFocus and onBlur Q:To delete an element from an array of Option objects attached to a DOM Select object, you set its reference equal to which one of the following? -1 null 0 NaN false  

ANS; null  

 

 

 

 

Q:var x; var y; x = new Array(3); x[0] = 1; x[1] = 2; x[2] = 3;

Page 57: Javascript

57  

y = new Array(3); y[0] = 1; y[1] = 2; y[2] = 3;

Referring to the above, which one of the following is true? x.toString() == y.toString() x.equals(y) x == y x equals y None of the above ANS: x.toString() == y.toString()  

 

Which one of the following is a DRAWBACK of JavaScript? It cannot be copy-protected. It does not work with Html forms. It is platform independent. It only works with Netscape browsers. It does not work with CGI. ANS: It cannot be copy-protected. Q:var index = 0; do { index++; document.writeln(index);

Page 58: Javascript

58  

} while (index < 10); Which one of the following code segments is equivalent to the code above?

1. var index = 1; do { document.writeln(++index); } while (index <= 10);

2. for (var index = 1; index <= 10; index++) document.writeln(index);

3. for (var index = 0; index < 10; index++)

document.writeln(index);

4. var index = 0; do { document.writeln(++index); } while (index <= 10);

5. var index = 0; do { document.writeln(index++); } while (index < 10);

6. ANS: for (var index = 1; index <= 10; index++) document.writeln(index);

Q:<A HREF="#" onMouseOver="status='Example';">test</a> Referring to the above code, when the "onMouseOver" event fires, the status line displays which one of the following? The word "test"

Page 59: Javascript

59  

The "#" symbol The current document URL with a "#" after it The current document URL with "Example" after it The word "Example" ANS: The current document URL with a "#" after it Example  

 

 

 

  

All Objects 

 

4   OBJECT: Textarea  

 

A Textarea object provides a multi-line field in which the user can enter data and is created with every instance of an HTML <TEXTAREA> tag on a form. These objects are then stored in the elements array of the parent form and accessed using either the name defined within the HTML tag or an integer (with '0' being the first element defined, in source order, in the specified form). PROPERTIES defaultValue Property This property sets or returns a string indicating the initial value of the Textarea object. The value of this property initially reflects the value between the start and end <TEXTAREA> tags. Use of the defaultValue property, which can be done at any time, will override the original value. Syntax: object.defaultValue[ = "newdefaultvalue"] form Property This property returns a reference to the parent Form of the Textarea object.

Page 60: Javascript

60  

Syntax: object.form name Property This property sets or returns the value of the Textarea object's name attribute. Syntax: object.name type Property Every element on a form has an associated type property. In the case of a Textarea object, the value of this property is always "textarea". Syntax: object.type value Property This property sets or returns the Textarea object's value attribute. This is the text that is actually displayed in the Textarea and can be set at any time with any changes being immediately displayed. Syntax: object.value METHODS blur Method This method removes the focus from the specified Textarea object. Syntax: object.blur( ) focus Method This method gives focus to the specified Textarea object. Syntax: object.focus( ) handleEvent Method This method calls the handler for the specified event. Syntax: object.handleEvent(event) select Method This method is used to select and highlight all or a portion of a text in a Textarea element. Used in conjunction with the focus method, this makes it easy to prompt the user for input and places the cursor in the correct place. Syntax: object.select( ) EVENT HANDLERS onBlur Event handler This event handler executes some specified JavaScript code on the occurrence of a blur event (when the Textarea object loses focus).

Page 61: Javascript

61  

Syntax: object.onBlur="myJavaScriptCode"  onChange Event handler This event handler executes some specified JavaScript code on the occurrence of a change event (when the Textarea object loses focus and its value has altered). Syntax: object.onChange="myJavaScriptCode"  onFocus Event handler This event handler executes some specified JavaScript code on the occurrence of a focus event (when the Textarea object receives focus). Syntax: object.onFocus="myJavaScriptCode"  onKeyDown Event handler This event handler executes some specified JavaScript code on the occurrence of a KeyDown event (when a key is depressed). Syntax: object.onKeyDown="myJavaScriptCode"  onKeyPress Event handler This event handler executes some specified JavaScript code on the occurrence of a KeyPress event (when a key is depressed and held down). Syntax: object.onKeyPress="myJavaScriptCode"  onKeyUp Event handler This event handler executes some specified JavaScript code on the occurrence of a KeyUp event (when a key is released). Syntax: object.onKeyUp="myJavaScriptCode"  onSelect Event handler This event handler executes some specified JavaScript code on the occurrence of a select event (when some text in the Textarea is selected). Syntax: object.onSelect="myJavaScriptCode" 

 

someText = 'JavaScript1.2'; pattern = /(\w+)(\d)\.(\d)/i; outCome = pattern.exec(someText); Referring to the above code, after execution, what does outCome[0] contain?

Page 62: Javascript

62  

true false /(\w+)(\d)\.(\d)/I undefined JavaScript1.2 ANS: JavaScript1.2  

 

Which one of the following is NOT a property of the password object? defaultValue Type Length Name Value ANS: Length                           Password has a property caleed maxLength and not length. 

 

Q:function setBanner() { if(document.images) { bannerImg = new Image; bannerImg.src = 'bluebanner.gif'; return (bannerImg.src); } return(""); } Referring to the above code, when does the script reach the line return("")?

Page 63: Javascript

63  

When document.images != null When the browser does not recognize the images object When the browser is not javascript-enabled When setBanner() is called When all the code above has executed

ANS: When the browser does not recognize the images object

 

Q:Which one of the following properties is the same as document.location.href? document.href top.link.href document.URL document.link.href window.document.href  

ANS: document.URL  

Q:FORM METHOD="GET" ACTION="/cgi-bin/process.pl"> <INPUT TYPE="submit" onClick="processClick(); return false;" onSubmit="processSubmit(); return true;"> </FORM>

In the above code, if the submit button is pressed, what code executes? None processSubmit() function

Page 64: Javascript

64  

processClick() function Both processSubmit() and processClick() functions An error occurs. ANS processClick() function  

 

 

Q:Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- function functionCall(f){ top.document.title = f.TestSelect.options[f.TestSelect.selectedIndex].value; } // --> </SCRIPT> <FORM> <SELECT NAME="TestSelect" onChange="functionCall(this.form);"> <OPTION VALUE="This is option 1">Option 1</OPTION> <OPTION VALUE="This is option 2">Option 2</OPTION> <OPTION VALUE="This is option 3">Option 3</OPTION> </SELECT> </FORM> What does the above script do in Internet Explorer? It changes the title of the top level document to the value of the selected option. It changes the title of the document in all open browser windows. It outputs the selected title to the document's window. It changes the selected index to the value of the selected option. It changes the title of the document in the current frame. Ans: It changes the title of the top level document to the value of the selected option 

Page 65: Javascript

65  

How can you get the width of the user's screen in JavaScript? self.getWidth() self.width self.screen.width self.document.getWidth() self.get("width") ANS:Self.width 

self.screen.width  

Sample Code function test(x, y) { return (Math.sqrt(x*x + y*y)); } function test2(x, y) { return (x ^ y); } document.writeln(test2(test(3,4),3));

What does the above code print?

2

4

6

25

125 ANSWER:6

Code var x=0; var y=0; var z=0; x = 1; x = (-x + y++) * ++z;

What is the value of "x" after execution of the code above?

-2

-1

0

1

2

Page 66: Javascript

66  

ANSWER:-1

Q:For which one of the following is the default keyword used?

To create a default function

To import the default style for the document

To execute the default code in a switch statement

To specify a default document if an href is incorrect

To use the default JavaScript files for the site ANSWER: To execute the default code in a switch statement

Sample Code <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- self.onerror = function() { self.document.location = "/errorpage.html"; return true; } // --> </SCRIPT> </HEAD>

What does the above code do?

It loads up errorpage.html when the page with this script is first loaded. If there is an error in the document, it loads up errorpage.html. It creates an error because the window object does not have an onerror

property.

If there is an error in any window, it loads up errorpage.html. It creates an error because the self object does not have an onerror

property.

ANSWER: If there is an error in the document, it loads up errorpage.html. 

Code var sample = "test"; sample.big().blink().bold().strike(); sample=sample.fontsize(7); document.write(sample.italics());

Referring to the above code, the document shows the word "test" with what style characteristics?

Size 7, blinking, bold, strikethrough, and italic

Size 7 and italic only

Page 67: Javascript

67  

Italic only

Blinking, bold, strikethrough, size 8, and italic

Default for the document ANSWER: Size 7 and italic only

Sample Code var season; /* code segment */ switch (season) { case 1: document.writeln("Winter"); break; case 2: document.writeln("Spring"); break; case 3: document.writeln("Summer"); break; case 4: document.writeln("Autumn"); }

Which one of the following code segments always will output "Summer" in the code above?

season = 4;

season = Math.ceil(Math.random() * 4);

season = "Winter";

season = Math.ceil(Math.random()) * 3;

season = "Summer"; ANSWER: season = Math.ceil(Math.random()) * 3;

var test = "Navigator"; test=test.substring(3,0);

Referring to the above code, what is the value of "test" after execution?

Nav

Naviga

iga

tor

igator ANSWER: NAV

Q:<FORM><INPUT TYPE=text name="first" onChange="echo(this.form,this.name);"> <INPUT TYPE=text name="second" onChange="echo(this.form,this.name);"> </FORM><SCRIPT language=javascript>

Page 68: Javascript

68  

function echo(form,currentfield) { if(currentfield == "first") form.second.value=form.first.value; else form.first.value=form.second.value; } </SCRIPT>

Function echo() above does which one of the following?

It copies the text from the second field to the first.

It moves the text from the second field to the first.

It moves the text from the first field to the second.

It swaps the text entered between fields.

It copies the text from the first field to the second. ANSWER: It copies the text from the first field to the second. It swaps the text entered between fields 

What does the referrer property of the document object contain?

The history object

The URL that linked to the current document

The current URL

The URL in the URL line in the browser

The name of the window that opened the document

ANSWER: The URL that linked to the current document

 

What does the value of a reset button contain?

The button object

The button label

The button type

The reset property

The button name The button label

       

Page 69: Javascript

69  

JavaScript Features A can not directly access client computer resources

B can not collect or give out passwords

C can not access other computers remotely

D uses 40 bit encryption

Referring to the above code, JavaScript security is enhanced because of which one of the following pairs?

A and B

B and C

C and D

A and C

B and D

ANS:  A and C 

 

What properties contain the name and version of the browser in use?

document.cookie

navigator.appName and navigator.appVersion

document.host and document.hostVersion

browser.name and browser.version

This information is not readily available.

ANS: navigator.appName and navigator.appVersion 

 

Code <A HREF="#" onMouseOver="status='Example';">test</a>

Referring to the above code, when the "onMouseOver" event fires, the status line displays which one of the following?

The word "test"

The current document URL with "Example" after it

The current document URL with a "#" after it

The word "Example"

The "#" symbol

ANS:

The current document URL with a "#" after it The word "Example"

Page 70: Javascript

70  

The alert method belongs to which object?

location

document

window

It does not belong to any object.

input

ANS: window 

 

 

Code function wContent(thisPage) { parent.content.document.write("<BODY>"); parent.content.document.write("Page "+ thisPage+"."); parent.content.document.close(); }

Referring to the above code, what code writes content into the main window?

<A HREF="javascript:wContent(1)">Page1</A>

<A HREF="wContent(1)">Page1</A>

<A HREF="document.wContent(Page1)">Page1</A>

<A HREF="parent.document.wContent(Page1)">Page1</A>

<A HREF="parent.wContent(1)">Page1</A>

ANS: Don’t know <A HREF="javascript:wContent(1)">Page1</A>

num = 0; while(num<10) { num++; }

How many times does the above "while" loop iterate?

9

10

At least 9

At least 10

Page 71: Javascript

71  

It is impossible to tell. ANS: 10

What statement is used to declare an integer named cnt?

Variable cnt;

Integer cnt;

Number cnt;

var cnt;

int cnt;

ANS: var cnt;

Sample Code testText = "This is"; testMessage = testText + " " + new Number(4) + " pages long!";

What is contained in testMessage after the above code segment is executed?

"This is Number:4 pages long!"

"This is (4) pages long!"

"This is 4 pages long!"

An error will occur because a number is added with a String.

"This is Number(4) pages long!"

ANS: "This is 4 pages long!"

Sample Code document.form[0].action = "cgi-bin/process.cgi";

What does the above code segment do?

It submits the first form.

It changes the script that processes the first form's results.

It changes the first form's method of submitting.

It changes the first form's display within the browser.

It changes the order in which the forms are processed.

Page 72: Javascript

72  

ANS: It changes the script that processes the first form's results.

It changes the first form's method of submitting. 

The event method "setTimeout(code, time)" is a method belonging to which one of the following objects?

location

document

window

It does not belong to any object.

form

ANS: window 

Which property of a frame is referenced by a link's target property?

parent

href

self

location

name

 

ANS: href 

name 

 

Which definition of the event handler for "onreset" for a form named "TestForm" is correct?

document.TestForm.onreset.function = { /* code here */ };

document.TestForm.onreset(function() { /* code here */ });

document.TestForm.onreset(new Function({ /* code here */ }));

document.TestForm.onreset.function = new Function({ /* code here */ });

document.TestForm.onreset = function() { /* code here */ };

 

 

ANS: document.TestForm.onreset = function() { /* code here */ }; 

Page 73: Javascript

73  

Which property is used to access the number of elements in a form?

elements

method

length

number

count

ANS: length

 

JavaScript's built-in client-side objects provide which one of the following? Multiple levels of abstraction Access to parts of the loaded HTML document A procedural interface for BASIC programmers Access to machine-specific system parameters Multi-threaded applications ANS: Access to parts of the loaded HTML document  

 

 

Sample Code <SCRIPT LANGUAGE="JavaScript"> <!-- var first = true, second = false; if (first && second) /* code segment 1 */ else if (first || second) /* code segment 2 */

Page 74: Javascript

74  

else if (second && first) /* code segment 3 */ else if (second || first) /* code segment 4 */ else /* code segment 5 */ // --> </SCRIPT> Which of the above code segments gets executed? Code segment 1 Code segment 2 Code segment 3 Code segment 4 Code segment 5 ANS: 2

 

Sample Code top.frames[1].location.href = "test.html"; What does the above code segment do? It loads the first frame from the top window with 'test.html'. It loads the second frame from the current window with 'test.html'. It loads the second frame from the top window with 'test.html'. It prepares the 'test.html' document for loading. It loads the first frame from the current window with 'test.html'. ANS: It loads the second frame from the top window with 'test.html'.  

var w = 0; var x = new Object(); var y = "String";

Page 75: Javascript

75  

var z = 4; if ((typeof x == "object") && (x.constructor == Object)) w += 1; if ((typeof y == "object") && (y.constructor == String)) w += 2; if ((typeof z == "object") && (z.constructor == Number)) w += 4; Referring to the above, what is the value of w? 0 1 2 3 4 ANS: w=1 

 

How do you refer to the first form in the first frame if your script is in the second frame? self.frames[0].form[0] parent.frames[0].form[0] self.frames[1].form[1] top.frames[1].form[1] parent.frames[1].form[1]

Page 76: Javascript

76  

ANS: parent.frames[0].form[0]  

Which one of the following is true of the "+" operator when applied to strings. It concatenates the strings into a new string object. It is invalid and produces an error. It sums the binary equivalent of the characters from both strings. It modifies the first string to include the second string. It adds the lengths of the two strings.  

ANS: It concatenates the strings into a new string object.  

appCodeName The code name of the browser.

appName The name of the browser (ie: Microsoft Internet Explorer).

appVersion Version information for the browser (ie: 4.75 [en] (Win98; U)).

cookieEnabled Boolean that indicates whether the browser has cookies enabled.

language Returns the default language of the browser version (ie: en-US). NS and Firefox only.

mimeTypes[] An array of all MIME types supported by the client. NS and Firefox only.

platform[] The platform of the client's computer (ie: Win32).

plugins An array of all plug-ins currently installed on the client. NS and Firefox only.

systemLanguage Returns the default language of the operating system (ie: en-us). IE only.

userAgent String passed by browser as user-agent header. (ie: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1))

userLanguage Returns the preferred language setting of the user (ie: en-ca). IE only.

 

Page 77: Javascript

77  

 

 

 

 

 

 

 

 

 

Code a. var length = parseInt('8'); b. var length = '8'; c. length = 1 + '8'; d. length = 8;

Referring to the above code, which lines declare variable "length" with a number data type?

a and b

b and c

c and d

a and d

b and d ANS: a and b

<FORMaction="someAction " method="POST" name="TestForm"> <SELECT name="TestSelect" MULTIPLE > <OPTION selected>Option 1</OPTION> <OPTION>Option 2</OPTION> <OPTION>Option 3</OPTION> <OPTION selected>Option 4</OPTION> <OPTION>Option 5</OPTION> </SELECT> </FORM>

Given the above, what is the value of document.TestForm.TestSelect.length?

1

Page 78: Javascript

78  

2

3

4

5

ANS: 5 

 

 

 

 

 

How do you create a new DOM cookie?

Clone another cookie.

Call document.newCookie().

Assign values to the document.cookie property.

Reset the expiration date on an existing cookie.

Call newCookie(). ANS: Assign values to the document.cookie property.

Sample Code <FORM METHOD="GET" ACTION="http://somewhere.on.net"> <INPUT TYPE="submit" onClick="history.go(-3); return false;"> </FORM>

Where does clicking the submit button in the above code take you?

"somewhere.on.net" main page

"somewhere.on.net" main page, then back three pages

Back three pages

Back three pages, then to the "somewhere.on.net" main page

It will give a JavaScript error. ANS: Back three pages

Which one of the following is NOT a JavaScript method used to emulate an event?

submit()

select()

load()

Page 79: Javascript

79  

focus()

click() ANS: submit() ??

Code <FORM> <INPUT type=button name=Reload value=Reload onClick="loadOver();"> </FORM><SCRIPT language=javascript> function loadOver() { code here } </SCRIPT>

Referring to the above code, what statement inside function loadOver() causes button "Reload" to emulate the Refresh button of a browser?

parent.ctr.location="javascript:location.reload()"

self.counter.location="location.history(0)"

location.reload()

document.location.href = this

parent.history(0) ANS: location.reload()

 

 

Sample Code var x = 1; x = new Function("x", "y", "return 4;");

What is the value of x.length after executing the above code segment?

0

1

2

3

4 ANS: 2

What do server-side session objects generally use on the client side to keep track of the user's session?

document.referrer document.session

Page 80: Javascript

80  

The history object. cookies The window object.

ANS: cookies

Cookies and Sessions - Session variables are maintained as cookies on the client so the client browser must have cookies enabled in order for the server to maintain session variables, otherwise the server sees every access by the same client as a new session when cookies are disabled. The server script can test whether session state is being maintained (i.e. cookies enabled) by:

1. setting a session variable, 2. immediately invoke another ASP that tests if the session variable is

still defined, 3. if not defined then most likely the browser isn't accepting cookies.

 

 

 

What code captures the user's name, or "Name," if the user clicks OK WITHOUT entering a name?

alert("Hello, " + confirm("Enter Your Name:"))

alert("Hello, " + alert("Enter Your Name:"))

alert("Hello, " + prompt("Enter Your Name:","Name") + ".")

prompt("Hello, " + prompt("Enter Your Name:","Name") ".")

alert("Hello, ") + prompt("Enter Your Name:") ANS: alert("Hello, " + prompt("Enter Your Name:","Name") + ".")

document.write('<IMG SRC="t.gif">'); document.writeln("<BR><PRE>Test"); document.write("JS!</PRE>");

Which one of the following is equivalent to the above code?

document.writeln(<IMG SRC="t.gif">Test\nJS!)

document.write('<IMG SRC="t.gif"><BR>Test\nJS!')

document.writeln('<IMG SRC="t.gif">')<BR><PRE>Test\nJS!</PRE>

document.write('<IMG SRC="t.gif"><BR><PRE>Test\nJS! </PRE>')

Page 81: Javascript

81  

document.write("<IMG SRC="t.gif">Test\nJS!")

ANS:

document.write('<IMG SRC="t.gif"><BR><PRE>Test\nJS! </PRE>')

Which one of the following is the form object's only method?

send()

submit()

click()

focus()

select()

ANS: submit()

What code always brings window "newWindow" to the front?

newWindow.position(top)

newWindow.focus()

setPosition.newWindow.top

newWindow.Visibility(top)

onFocus.newWindow.show

ANS: newWindow.focus() 

Other than a checkbox, which other form element has a "checked" property?

hidden

select

input

option

radio

ANS: radio 

Code <script language=javaScript>

Page 82: Javascript

82  

function surfto(form) { var idx=form.s1.selectedIndex if(form.s1.options[idx].value != 0) location=form.s1.options[idx].value; } </SCRIPT><FORM name="form1"> <SELECT name=s1 onChange="surfto(this.form)" size=1> <OPTION selected value=0>Choose One <OPTION value=u2.htm>U2 <OPTION value=u3.htm>U3 <OPTION value=u4.htm>U4</SELECT> </FORM>

Which one of the following does the above code create?

Four hyperlinks

Four buttons, each loading a corresponding URL when clicked

Four check boxes and a button that loads the selected document when clicked

A pull-down menu and a button that loads the selected document when clicked

A pull-down menu with four choices that loads a selected when focus is removed

 

 

When the following code is executed in Netscape: x = new Java.lang.Double(2.05); what type of object is x?

Double

var ans

JavaObject

Number

Float JavaObject

 

var x = 15%4;

Referring to the above code, what is the value of variable "x"?

0

1

2

3 ans

4

 

 

Which one of the following objects is NOT a form element?

Page 83: Javascript

83  

password

input

link

select

hidden

Ans :link 

 

 

Sample Code var x; x = Array(2,5,10);

Referring to the above, how many elements are in the array x?

3

4

10

11

100

 

Ans :3 

 

Code <form name=f1> <input type="text" name="a"> <input type="text" name="b"> </form>

Referring to the above code, what code initially places the cursor in text field "a"?

<HEAD onLoad="this.document.f1.focus();">

<BODY Select="document.f1.a.select();">

<BODY onChange="this.document.f1.select();">

<BODY onLoad="this.document.f1.a.focus();">

<HEAD setFocus="document.f1.a.focus();">

Page 84: Javascript

84  

Ans: <BODY onLoad="this.document.f1.a.focus();"> 

delete car.fivespeed;

The above code deletes which one of the following?

The car class

The fivespeed property from the car class

The fivespeed property from object car

Object car

Nothing Ans The fivespeed property from object car

function Pass() { document.jane.elements[0].value= document.joe.elements[0].value; } <FORM name=joe> <INPUT type=text size=30></FORM> <FORM><INPUT type=button value="Click Me" onClick="Pass()"></FORM> <FORM name=jane> <INPUT type=text size=30></FORM>

Q Referring to the above code, what happens to the text when the user types "Hello" into the first text control and then clicks the button?

Nothing, function "Pass()" contains an error.

It is moved to the second text control.

It is left in the first text control.

It is deleted from the first text control.

It is copied to the second text control.

Ans: It is copied to the second text control.

Following are some questions… whose answers are unknown…..

Page 85: Javascript

85  

Page 86: Javascript

86  

 

Page 87: Javascript

87  

 

Page 88: Javascript

88  

 

Page 89: Javascript

89  

 

Page 90: Javascript

90  

 

Page 91: Javascript

91