question archive 1) Assuming you have a radio button with an id of “contact_via”, which of the following statements selects that radio button? $("contact_via")
Subject:Computer SciencePrice:4.87 Bought7
1) Assuming you have a radio button with an id of “contact_via”, which of the following statements selects that radio button?
$("contact_via").selected = true; |
|
$("contact_via").checked = true; |
|
$("contact_via").value = true; |
|
$("contact_via").enabled = true; |
2. Why would the following code for a button not send the form data to the server?
<input type="button" value="Register" id="register">
The value of the id attribute should be “submit”. |
|
The name attribute is missing. |
|
The value of the type attribute should be “submit”. |
|
The submit attribute is missing. |
3. What does the following code do?
$("email").firstChild.nodeValue = "Entry is invalid.";
Sets the text for the element with “email” as its id attribute. |
|
Gets the text for the element with “email” as its id attribute. |
|
Sets the text for the first child of the element with “email” as its id attribute. |
|
Sets the text for the next child of the element with “email” as its id attribute. |
4. For the following code, an event handler named investmentChange is
var investmentChange = function() {
var years = parseInt( $("years").value );
alert("Years: " + years);
};
window.onload = function() {
$("investment").onchange = investmentChange;
};
attached to the onload event of the global window object |
|
attached to the onload event of a control with an id of “investment” |
|
attached to the onchange event of the global window object |
|
attached to the onchange event of a control with an id of “investment” |
5. Given HTML that includes the element
<p id = "ship">shipping cost goes here</p>
what will the following code do if the user enters 100 at the prompt?
var getInfo = function() {
var cost = parseFloat(prompt("How much does the item cost?"));
var ship = cost * .06;
document.getElementById("ship").innerHTML="Shipping: $" + ship.toFixed(2);
};
It will display “shipping cost goes here Shipping: $6.00” in the <p> element. |
|
It will replace the text in the <p> element with “Shipping: $6.00”. |
|
It will display NaN in the <p> element because the starting text in this element is not a number. |
|
It will calculate the value of the ship variable, but the <p> element will remain unchanged. |
6. To view the changes that have been made to the DOM for a page by the JavaScript, you can
display the HTML for the page in a browser |
|
display the HTML for the page in Chrome’s Sources panel |
|
display the HTML for the page in Chrome’s Elements panel |
|
none of the above |
7. What does the following line of code do?
$("user").innerHTML = "Hello, good friend!";
It sets the content of the element with “user” as its id attribute to “Hello, good friend!” |
|
It sets the value property of the element with “user” as its id attribute to “Hello, good friend!” |
|
It gets the content of the element with “user” as its id attribute and appends “Hello, good friend!” to that content. |
|
It gets the value property of the element with “user” as its id attribute and appends “Hello, good friend!” to that property. |
1)
Answer: $("contact_via").checked = true;
Explanation: If the $("contact_via").checked is set to true then the radio button with an id of “contact_via” get selected.
2)
Answer: The value of the type attribute should be “submit”.
Explanation: The <input> elements of type submit is used as a button. It submits the form to the server.
3)
Answer: Sets the text for the element with “email” as its id attribute.
Explanation: The code sets the text of an HTML element.
4)
Answer: attached to the onchange event of a control with an id of “investment”
Explanation: The code attaches the onchange event of a control with an id of “investment”.
5)
Answer: It will replace the text in the <p> element with “Shipping: $6.00”.
Explanation: The content of the paragraph is replaced with the new content by calling document.getElementById("ship") where ship is the id of the tag p.
6)
Answer: display the HTML for the page in Chrome’s Elements panel
Explanation: The Chrome’s Elements panel displays DOM structure of the current web page.
7)
Answer: It sets the content of the element with “user” as its id attribute to “Hello, good friend!”
Explanation: The code sets the text of an HTML element.