Upwork DHTML Test

1. After clicking on a link, your main browser window spawns a small new window and writes 
some text on it. When both the window page sources are viewed, the small window page source 
seems identical to that of the large one. Which of the following makes this happen?
Answers:
• The function writing to the new window did not close the document stream
• Windows receive the source code of the window that wrote to them
• Since the new window has no filename, it receives the source code of its parent
• None of the above
Answers:
• True
• False
3. How would you double the image size of an Image on a mouseover event, if the original 
width and height are 100px and id is logo?
Answers:
• document.getElementById('logo').style.width="200" document.getElementById('logo').style.height="200"
• document.getElementById('logo').style.width="100" document.getElementById('logo').style.height="100"
• document.getElementById('logo').width="200" document.getElementById('logo').height="200"
• document.getElementById('logo').width="200px" document.getElementById('logo').height="200px"
4. Choose another way to write x ? a = b : a = c
Answers:
• if ('x') { a = b; } else { a = c; }
• if (x) { a = c; } else { a = b; }
• x : a = c ? a = b
• None of the above
5. For making the text transparent, the mask filter can be used like:
Answers:
• mask(color=#ff00ff)
• mask(color=#ffffff)
• mask(#ffffff)
• mask(#ff00ff)
6. Your website displays a few articles on java programming. If you want to leave '1 cm' 
space above and below the code blocks, you would use code { margin-top:1cm ; 
margin-bottom:1cm }.
Answers:
• True
• False
7. Consider the following validate function:

<script type="text/javascript">
function ValidateField()
{
        if(document.forms[0].txtId.value =="")
                {return false;}

        return true;
}
</script>

This function should be called as soon as the user leaves the field. What will you do?
Answers:
• <input name=txtId type="text" onreset="return ValidateField()">
• <input name=txtId type="text" onfocus="return ValidateField()">
• <input name=txtId type="text" onsubmit="return ValidateField()">
• <input name=txtId type="text" onblur="return ValidateField()">
8. An HTML form has 10 checkboxes which are all named "chkItems". Which JavaScript function 
can be used for checking all the checkboxes together?
Answers:
• function CheckAll() { for (z = 0; z < document.forms.chkItems.length; z++) { document.forms.chkItems[z].checked=true } }
• function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) { document.forms[0].chkItems[z].checked=true } }
• function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) { document.forms[0].chkItems.list[z].checked=true } }
• function CheckAll() { for (z = 0; z < document.forms[0].chkItems.length; z++) { document.forms[0].chkItems.list[z].checked=false } }
9. Following is a sample CSS style:

1. p
2. (
3. font-family:arial
4. color:black
5. text-align:left
6. );

What are the corrections required in this style?
Answers:
• The style definition should be enclosed in curly braces
• Multiple items within a style should be separated by ";"
• The style should not close with a semicolon
• All of the above
10. Consider an HTML form with a checkbox and a text field. When data is entered and the 
Enter key is pressed, the data seems to be lost before the user can click on the button 
that calls the processing function. How would you correct this programatically?
Answers:
• Add a TYPE=HIDDEN INPUT to the form
• Trap the Enter keypress and return (null)
• Add 'return false' to onsubmit="..." in the FORM tag
• Instruct the user not to press the Enter key
• Modify the ENCTYPE property of the form
11. Given below is a window.open function:

        window.open(url,name,"attributes")

How will you ensure that different URLs open in the same window?
Answers:
• By keeping the second attribute name same
• By nullifying the name attribute
• By omitting the name attribute
• None of the above
12. Consider the three variables:

someText = 'JavaScript1.2';
pattern = /(\w+)(\d)\.(\d)/i;
outCome = pattern.exec(someText);

What does pattern.ignoreCase contain?
Answers:
• true
• false
• undefined
• null
• 0
13. DHTML uses a combination of:
Answers:
• HTML
• A scripting language
• Cascading style sheets
• All of the above

82 NOT Answered Yet Test Questions:

(hold on, will be updated soon)
14. The width of H1 is defined as follows:

H1 {width:100px;}

How can you make the heading flip horizontally?
Answers:
• <h1 filter(flip)>Heading</h1>
• <h1 style="filter::fliph()">Heading</h1>
• <h1 style="filter:fliph()">Heading</h1>
• <h1 style="FliphFilter()">Heading</h1>
15. Which of the following statements is true with regard to setTimeout()?
Answers:
• The statement(s) it executes run(s) only once
• It pauses the script in which it is called
• clearTimeout() does not stop its execution
• It is required in every JavaScript function
16. Which of the following is not a JavaScript event?
Answers:
• onabort
• onchange
• onupdate
• onkeydown
17. Which of the following helps you create hyperlinks without an underline?
Answers:
• a{text-decoration:none}
• a{text-decoration:noline}
• a{text-decoration:hide}
• a{text-decoration:invisible}
• a{ font-style: normal;}
• a{font-style: none;}
18. Which of the following is not a CSS filter?
Answers:
• alpha
• beta
• xray
• invert
19. Which of the following enables JavaScript Document Object Model to provide access to 
the HTTP header?
Answers:
• document.GetHeader()
• document.getId('header')
• document.getElementByName('header')
• document.getElementById('header')
• You cannot read the HTTP header information using JavaScript
20. How would you change the image position from absolute to relative, if the image id is 
"ERImage"?
Answers:
• document.getElementById('ERImage').position="relative"
• document.getElementById('ERImage').setAttribute("position", "relative")
• document.getElementById('ERImage').style.position="rel"
• document.getElementById('ERImage').style.position="relative"
21. Which of the following properties of JavaScript is used to store the extra values for 

DHTML tricks?
Answers:
• DHTML
• HTML
• innerHTML
• outerHTML
22. This is a JavaScript function for changing the color of the text box named "txtName":

function SetColor(col)
{ document.forms[0].txtName.style.background=col }

How will you change the color of the text box txtName to green, only for the time that 
the user is pressing any key?
Answers:
• <input type="text" onkeydown="SetColor('white')" onkeyup="SetColor('green')" name="txtName">
• <input type="text" onkeydown="SetColor('green')" onkeyup="SetColor('white')" name="txtName">
• <input type="text" onkeydown="SetColor('green')" name="txtName">
• <input type="text" onkeydown="SetColor('white')" name="txtName">
23. Which of the following properties is used to redirect a visitor to another page?
Answers:
• document.URL
• window.location.href
• document.location.href
• link.href
• window.location
24. Which of the following can you use to accept user input?
Answers:
• The prompt method
• The alert method
• A form field
• The confirm method
25. Which of the following code snippets is more efficient and why?

<script language="javascript">
     for(i=0;i<document.images.length;i++)
          document.images[i].src="blank.gif";

</script>


<script language="javascript">
     var theimages = document.images;
     for(i=0;i<theimages.length;i++)
          theimages[i].src="blank.gif"
</script>
Answers:
• Both are equally efficient
• The first code is more efficient as it contains less coding
• The first code is more efficient as it employs object caching
• The second code is more efficient as it employs object caching
26. Which of the following statements with regard to CSS is correct?
Answers:
• The positioning can be absolute, relative, or dynamic
• The float property for text/image can be left, right, or center
• The values for visibility can be true or false
• The display property sets how an element is displayed
27. Which of the following helps you highlight some of the running text on a web page?
Answers:
• <span style="background-color:yellow">
• <span style="background-highlight:yellow">
• <span style="background:yellow">
• <span style="highlight-color:yellow">
28. You want to move all the paragraphs 30px towards the right relative to their normal 
position. The style definition should be:
Answers:
• p.relt{ position:relative; left:30px;}
• p.relt{ position:relative; left:-30px;}
• p{ position:relative; left:30px;}
• p{ position:relative; left:-30px;}
29. Which of the following is not considered a part of DHTML?
Answers:
• JavaScript
• CSS
• HTML
• VBScript
• All are part of DHTML
30. You do not want the end user to see the JavaScript code embedded in the HTML file when 
the user views the source of the HTML page. Which of the following helps you achieve this?
Answers:
• This is not possible
• Use externally linked files which hold the JavaScript code
• Modify the headers of the page
• Change the MIME type of the page
31. You want to move some selected paragraphs 15px towards the left relative to their 
normal position. The style definition should be like:
Answers:
• p.relt{ position:relative; left:15px;}
• p.relt{ position:relative; left:-15px;}
• p{ position:relative; left:15px;}
• p{ position:relative; left:-15px;}
32. How would you randomly choose an element from an array named myStuff if the number of 
elements changes dynamically?
Answers:
• randomElement = myStuff[Math.floor(Math.random() * myStuff.length)];
• randomElement = myStuff[Math.ceil(Math.random() * myStuff.length)];
• randomElement = myStuff[Math.random(myStuff.length)];
• randomElement = myStuff[Math.ceil(Math.random()*myStuff.length - 1)];
33. The anchor tag is defined as follows:

<a href="http://expertrating.com">expertrating</a>

Which of the following styles will make convert this to capital letters on mouseover?
Answers:
• a:hover { text:ucase;}
• a:hover { text-style:uppercase;}
• a:hover { text-transform:uppercase;}
• a:hover { text-style:upper;}
34. The width of h3 is defined as follow:

H3 {width:100%;}

How can you make the heading glow?
Answers:
• <h3 filter(glow)>Heading</h3>
• <h3 style="filter:glow()">Heading </h3>
• <h3 style="filter::glow()">Heading </h3>
• <h3 style="GlowFilter()">Heading </h3>
35. How will you display text as a superscript?
Answers:
• vertical-align: super
• vertical-align: superscript
• vertical-align: top
• text-align: super
• text-align: superscript
36. The width of h3 is defined as follows:

H3 {width:90%;}

How can you make the heading flip vertically?
Answers:
• <h3 filter(flip)>Heading</h3>
• <h3 style="filter:flipv()">Heading </h3>
• <h3 style="filter::flipv()">Heading </h3>
• <h3 style="FlipvFilter()">Heading </h3>
37. You want to shake a link on the mouseover event. If the style position is set to 
relative and the anchor id is lnk1, which of the following code lines will be useful with 
a timer?
Answers:
• document.getElementById('lnk1').left="0" document.getElementById('lnk1').left="2"
• document.getElementById('lnk1').style.left="0" document.getElementById('lnk1').style.left="2"
• document.getElementById('lnk1').style.move="0" document.getElementById('lnk1').style.move="2"
• document.getElementById('lnk1').right="0" document.getElementById('lnk1').right="2"
38. When does the load event of the browser occur?
Answers:
• When the browser receives the page header information
• When the browser starts displaying the content
• When the browser receives all the page information, including framesets
• When the browser receives all the page information, including framesets and displays it
• None of the above
39. Is the following statement correct?

The width of an element must be set for making filters work.
Answers:
• Yes
• No
40. What is the error in the statement var charConvert = toCharCode('x')?
Answers:
• toCharCode() is a bogus method
• Nothing. It will work fine
• toCharCode accepts only numbers
• toCharCode takes no arguments
41. You are required to create a web page in which hyperlinked sub-headings are displayed. 
On clicking a link, the contents should get displayed dynamically. Which of the following 
style attributes would you use for this?
Answers:
• visibility:hidden;
• visibility:display;
• visibility:visible;
• visibility:none;
42. Which of the following will you use for changing the color of a button with id=btn, to 
green on a mouseover event?
Answers:
• btn.color="green"
• document.getElementById('btn').color="green"
• document.getElementById('btn').style.color="black"
• document.getElementById('btn').style.color="green"
43. You have a button definition as given below:

<input class="a" type="button" value="Calculate">

To load an image "Img2.jpg" as the background of the button on a mouseover event, you can 
use:
Answers:
• event.srcElement.style.backgroundImage="Img2.jpg"
• event.srcElement.style.Image="Img2.jpg"
• event.srcElement.style.backgroundImage="url('Img2.jpg')"
• event.srcElement.style.Image="url('Img2.jpg')"
44. The anchor tag is defined as follows:

<a href="http://expertrating.com">expertrating</a>

Which of the following styles will increase the spacing between letters on mouseover?
Answers:
• a:hover { spacing: 1px;}
• a:hover { spacing: 2px;}
• a:hover { letter-spacing: 0;}
• a:hover { letter-spacing: 2px;}
45. How will you change the color of the paragraph text to blue on placing the mouse over 
the paragraph, and reset it back when the mouse leaves the paragraph?
Answers:
• <p onmouseover="style.color='black'" onmouseout="style.color='blue'"> The text of the paragraph..</p>
• <p onmouseover="style.color='blue'" onmouseout="style.color='black'"> The text of the paragraph..</p>
• <p onmouseout="style.color='blue'"> The text of the paragraph..</p>
• <p onmouseover="style.color='blue'"> The text of the paragraph..</p>
46. The form tag is defined as follows:

<form onsubmit="return Validate()" action="http://www.mysite.com/">

How will you implement the Validate() function that will stop the form from being submitted 
if the name field on the form is not filled?
Answers:
• <script type="text/javascript"> function Validate() { if(document.forms[0].name.value == "") return true; else return false; } </script>
• <script type="text/javascript"> function Validate() { if(document.forms[0].name.value == "") return false; else return true; } </script>
• <script type="text/javascript"> function Validate() { if(document.forms[0].name== "") return false; else return true; } </script>
• <script type="text/javascript"> function Validate() { if(document.forms[0].name == "") return true; else return false; } </script>
47. You are setting cookies with JavaScript. What happens to cookies.txt data if the file 
exceeds the maximum size?
Answers:
• Your script automatically generates a run-time error
• Your script automatically generates a load-time error
• The file is truncated to the maximum length
• None of the above
48. You are designing a web site and need to set the background image for all the web 
pages. You want a small background image to repeat and fill up the whole background. Which 
of the following body styles is ideal for this?
Answers:
• body { background: url(/images/bg.gif); repeat: repeat-x }
• body { background: url(/images/bg.gif); repeat: repeat-y }
• body { background-image: url(/images/bg.gif); background-repeat: no-repeat }
• body { background-image: url(/images/bg.gif);}
49. The following code snippet is used in form validation, the validate function is 
supposed to return a true if all validations are successful and false if the validation 
fails. However, the data is always submitted even if the validation fails, what could the 
cause be?


<form name="frmadd" method="post" action="add.asp" onsubmit="validate()">
Answers:
• There is no error, the code is fine
• There should be a return statement before the call to the validate function
• onsubmit="validate()" should be replaced with "javascript:validate()"
50. What will the following code snippet do?

<form onreset="alert('Please again fill the form')">
Answers:
• It validates the contents of the form
• It prompts the user not to leave the fields of the form empty
• It prompts the user to fill the form once the form is cleared
• None of the above

Comments