Which JavaScript code segment should you use?

You are developing a customer web form that includes the following HTML.
<label id=”txtValue”X/label>
Information from the web form is submitted to a webservice. The web service returns the following JSON object.
{
“Confirmation”: “1234”,
“FirstName”: “John”
}
You need to display the Confirmation number from the JSON response in the txtValue label field.
Which JavaScript code segment should you use?

You are developing a customer web form that includes the following HTML.
<label id=”txtValue”X/label>
Information from the web form is submitted to a webservice. The web service returns the following JSON object.
{
“Confirmation”: “1234”,
“FirstName”: “John”
}
You need to display the Confirmation number from the JSON response in the txtValue label field.
Which JavaScript code segment should you use?

A.
$(“#txtValue”).val = (JSONObject.Confirmation);

B.
$(“#txtValue”).val(JSONObject.Confirmation);

C.
$(“#txtValue”).text = (JSONObject.Confirmation);

D.
$(“#txtValue”).text(JSONObject.Confirmation);



Leave a Reply 8

Your email address will not be published. Required fields are marked *


FAITH

FAITH

The right answer is B

César Albuquerque

César Albuquerque

no, it’s ‘D’

xpto

$(“#LabelID”).text() //return xpto
$(“#LabelID”).val() //return “”

Steven Tran

Steven Tran

I believe the answer D is correct, val should be used in instances when text is being set on Input elements.

Chris

Chris

The right answer is D.
A label object has no value attribut.

clem

clem

D !

Difference between .val and .text to know – see .text() in jquery too!

cindy lou

cindy lou

The answer is D because .val() is used for form validation control. The form was already submitted in this scenario. The information is being returned in text format