Aspirant Academy

MCQ

Paper - II (xvi) — Web Development MCQ - Practice Questions with Answers

Solve 52 Paper - II (xvi) — Web Development questions for RAS/RPSC preparation.

Practice questions

Q1A developer wants a web page paragraph to change immediately after the user selects a value from a drop-down list, without reloading the page. Which combination most directly provides this Dynamic HTML behaviour?

A XML declaration with a stylesheet link only
B PHP variable assignment after the page has already reached the browser
C Only static HTML tags and server restart
D JavaScript event handling with DOM manipulation
Explanation

Dynamic HTML is the practical use of HTML structure, CSS presentation, and client-side scripting to change a page after it has loaded. For the given case, JavaScript listens for the drop-down's change event and then updates the paragraph node through the DOM. No full-page reload is needed.

Q2In the Document Object Model, what is the main conceptual importance of representing an HTML document as a tree of nodes?

A It prevents JavaScript from changing page content after loading.
B It makes every HTML page executable as PHP on the client.
C It removes the need for CSS selectors in a browser.
D It gives scripts a structured way to access elements, attributes, text, and events in the document.
Explanation

The DOM models a document as a rooted node tree. That structure is the basis for practical DHTML: JavaScript can find nodes, read or change their properties, add or remove content, and attach event listeners to user-interface elements.

Q3In a browser script, a developer stores the result of document.querySelectorAll(".notice") and then later adds another element with class="notice" to the document. Which statement is most accurate for standard DOM behavior?

A The method can select only by tag name, so the class selector is invalid.
B The stored result is updated only after calling document.write() once.
C The stored result remains a static NodeList; the new element is not automatically added to that already returned list.
D The stored result becomes a live HTMLCollection and immediately includes the new element.
Explanation

The DOM distinction being tested is live versus static collections. querySelectorAll evaluates the selector against the context and returns a static NodeList for that call. If new matching elements are inserted later, the code must query again or handle the inserted node directly. This is important in DHTML because dynamic updates can otherwise be missed by scripts that assume the saved list keeps changing.

Q4An HTML element is written as <p id="msg" class="warn" style="color: green">Text</p>. An external stylesheet contains #msg { color: red; } and .warn { color: blue; }. No !important declaration is used. What color will normally apply to the paragraph text?

A Green, because the normal inline style declaration outranks the external author rules in the cascade.
B The browser default color, because conflicting author rules cancel one another.
C Blue, because class selectors are evaluated after ID selectors.
D Red, because an ID selector always overrides inline style.
Explanation

CSS cascade questions often combine source, specificity, and placement. Here the class rule and ID rule are both normal author stylesheet declarations, while the style attribute is a normal inline declaration on the element itself. In the absence of !important, that inline declaration supplies the winning color, so the paragraph is rendered green.

Q5Which PHP statement safely starts outputting a submitted name in an HTML response by escaping special HTML characters?

A echo css_escape($_POST['name']);
B echo document.getElementById('name');
C echo $_POST['name'];
D echo htmlspecialchars($_POST['name']);
Explanation

When PHP inserts submitted form data into an HTML page, raw output can be interpreted as markup. htmlspecialchars is the standard PHP function used in basic examples to convert special characters before echoing the value.

You've seen 5 of 52 sample questions

Unlimited practice on Paper - II (xvi) — Web Development comes with the RAS Test Series + Practice pack or Gate Pass.

More questions

6In web page authoring, which statement best describes the Document Object Model used by JavaScript in a browser?

AIt is a PHP array that stores submitted form values on the server.
BIt represents an HTML or XML document as a tree of nodes that scripts can access and modify.
CIt is only the original HTML source file stored on the web server.
DIt is a CSS file that decides the final color and layout of all elements.

7In the context of DHTML, which combination most directly enables a menu item to change its appearance when the user clicks it?

AHTML for structure, CSS for presentation, and JavaScript with the DOM for event-driven changes
BPHP variables only, because server variables automatically update the page after every click
CHTML comments only, because comments can hide and show interface elements
DXML DTD only, because dynamic presentation is controlled by document type declarations

8In JavaScript, what is the result of `typeof [1, 2, 3]`?

A"object"
B"number"
C"array"
D"list"

9In PHP, a form is submitted with method="post" and contains <input name="email">. Which predefined variable is the usual direct source for reading the submitted email field on the receiving PHP page?

A$email
B$_POST["email"]
C$_GET["email"]
D$_COOKIE["email"]

10In a web page authoring task, a developer wants a text label to be programmatically associated with a text box so that clicking the label focuses the input. Which HTML pairing is the most appropriate?

A<label for="userName">Name</label><input id="userName" type="text">
B<p id="userName">Name</p><input label="userName" type="text">
C<label name="userName">Name</label><input for="userName" type="text">
D<span for="userName">Name</span><input name="userName" type="text">

11In PHP, an HTML form is submitted with `method="post"` and an input field named `email`. Which expression is normally used to read the submitted value in the processing script?

A$_POST['email']
B$_GET['email']
Cdocument.email.value
D$POST['email']

12Which XML fragment is well-formed?

A<book><title>Web</title><title>CSS</book>
B<book><title>Web</book></title>
C<book id="101"><title>Web</title></book>
D<book id=101><title>Web</title></book>

13A paragraph has both of the following CSS rules applied. Which color will be used for <p id="notice" class="alert">Text</p>? p { color: black; } .alert { color: red; } #notice { color: blue; }

Ablue, because the id selector is more specific than the class and element selectors
Bblack, because the element selector p is written first
Cno color, because three matching CSS rules make the declaration invalid
Dred, because a class selector always overrides an id selector

14Which JavaScript statement is most suitable for changing the displayed text inside an existing element with id="status" without reloading the page?

Aphp.echo('#status', 'Ready');
Bdocument.css('status').text = 'Ready';
Cdocument.getElementById('status').textContent = 'Ready';
Dwindow.location = 'Ready';

15Which PHP superglobal is normally used to read values submitted by an HTML form whose method is `post`?

A$_GET
B$_POST
C$_COOKIE
D$_SERVER

More topics in Networking & Web (Senior CI)

Explore other subjects